summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-08-27 16:23:06 +0300
committerAndrei Karas <akaras@inbox.ru>2014-08-27 16:23:06 +0300
commitd69abc43187ded70dce586d793a4dc1dbcd1010d (patch)
treea69ede97c82ba5dd7b2e2ed53f6dc9f7c221fbb9 /src
parent4455f3a3dd5fa28ef7fc1d1cf6d2bff723c90b47 (diff)
downloadmv-d69abc43187ded70dce586d793a4dc1dbcd1010d.tar.gz
mv-d69abc43187ded70dce586d793a4dc1dbcd1010d.tar.bz2
mv-d69abc43187ded70dce586d793a4dc1dbcd1010d.tar.xz
mv-d69abc43187ded70dce586d793a4dc1dbcd1010d.zip
Move chat command /uploadconfig into actions.
Diffstat (limited to 'src')
-rw-r--r--src/actions/actions.cpp73
-rw-r--r--src/actions/actions.h1
-rw-r--r--src/commands.cpp9
-rw-r--r--src/commands.h5
-rw-r--r--src/input/inputaction.h1
-rw-r--r--src/input/inputactionmap.h11
-rw-r--r--src/input/pages/other.cpp6
7 files changed, 92 insertions, 14 deletions
diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp
index 90429bc5b..8406f236e 100644
--- a/src/actions/actions.cpp
+++ b/src/actions/actions.cpp
@@ -38,6 +38,7 @@
#include "being/playerrelations.h"
#include "gui/chatconsts.h"
+#include "gui/dialogtype.h"
#include "gui/dialogsmanager.h"
#include "gui/gui.h"
#include "gui/popupmanager.h"
@@ -47,6 +48,7 @@
#include "gui/popups/popupmenu.h"
#include "gui/windows/buydialog.h"
+#include "gui/windows/okdialog.h"
#include "gui/windows/skilldialog.h"
#include "gui/windows/socialwindow.h"
#include "gui/windows/statuswindow.h"
@@ -81,9 +83,11 @@
#include "net/beinghandler.h"
#include "net/chathandler.h"
+#include "net/download.h"
#include "net/gamehandler.h"
#include "net/ipc.h"
#include "net/net.h"
+#include "net/uploadcharinfo.h"
#include "net/partyhandler.h"
#include "net/playerhandler.h"
#include "net/tradehandler.h"
@@ -98,6 +102,7 @@
#include "resources/map/map.h"
#include "utils/chatutils.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/timer.h"
@@ -118,6 +123,65 @@ extern char **environ;
namespace Actions
{
+static int uploadUpdate(void *ptr,
+ DownloadStatus::Type status,
+ size_t total A_UNUSED,
+ size_t remaining A_UNUSED)
+{
+ if (status == DownloadStatus::Idle || status == DownloadStatus::Starting)
+ return 0;
+
+ UploadChatInfo *const info = reinterpret_cast<UploadChatInfo*>(ptr);
+ if (status == DownloadStatus::Complete)
+ {
+ std::string str = Net::Download::getUploadResponse();
+ const size_t sz = str.size();
+ if (sz > 0)
+ {
+ if (str[sz - 1] == '\n')
+ str = str.substr(0, sz - 1);
+ str.append(info->addStr);
+ ChatTab *const tab = info->tab;
+ if (chatWindow && (!tab || chatWindow->isTabPresent(tab)))
+ {
+ str = strprintf("%s [@@%s |%s@@]",
+ info->text.c_str(), str.c_str(), str.c_str());
+ outStringNormal(tab, str, str);
+ }
+ else
+ {
+ // TRANSLATORS: file uploaded message
+ new OkDialog(_("File uploaded"), str,
+ // TRANSLATORS: ok dialog button
+ _("OK"),
+ DialogType::OK,
+ true, false, nullptr, 260);
+ }
+ }
+ }
+ delete2(info->upload);
+ delete info;
+ return 0;
+}
+
+static void uploadFile(const std::string &str,
+ const std::string &fileName,
+ const std::string &addStr,
+ ChatTab *const tab)
+{
+ UploadChatInfo *const info = new UploadChatInfo();
+ Net::Download *const upload = new Net::Download(info,
+ "http://sprunge.us",
+ &uploadUpdate,
+ false, true, false);
+ info->upload = upload;
+ info->text = str;
+ info->addStr = addStr;
+ info->tab = tab;
+ upload->setFile(fileName);
+ upload->start();
+}
+
impHandler(emote)
{
const int emotion = 1 + event.action - InputAction::EMOTE_1;
@@ -1073,4 +1137,13 @@ impHandler0(createItems)
return true;
}
+impHandler(uploadConfig)
+{
+ uploadFile(_("Uploaded config into:"),
+ config.getFileName(),
+ "?xml",
+ event.tab);
+ return true;
+}
+
} // namespace Actions
diff --git a/src/actions/actions.h b/src/actions/actions.h
index a288b7f86..dcaf043d9 100644
--- a/src/actions/actions.h
+++ b/src/actions/actions.h
@@ -84,6 +84,7 @@ namespace Actions
decHandler(testSdlFont);
#endif
decHandler(createItems);
+ decHandler(uploadConfig);
} // namespace Actions
#undef decHandler
diff --git a/src/commands.cpp b/src/commands.cpp
index e33a78fb6..fae194ee1 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -171,15 +171,6 @@ static void uploadFile(const std::string &str,
upload->start();
}
-impHandler(uploadConfig)
-{
- uploadFile(_("Uploaded config into:"),
- config.getFileName(),
- "?xml",
- event.tab);
- return true;
-}
-
impHandler(uploadServerConfig)
{
uploadFile(_("Uploaded server config into:"),
diff --git a/src/commands.h b/src/commands.h
index 907ed82d3..6ceb84d6c 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -52,7 +52,6 @@ struct CommandInfo final
namespace Commands
{
decHandler(hack);
- decHandler(uploadConfig);
decHandler(uploadServerConfig);
decHandler(uploadLog);
decHandler(gm);
@@ -63,8 +62,7 @@ namespace Commands
enum
{
- COMMAND_UPLOADCONFIG = 0,
- COMMAND_UPLOADSERVERCONFIG,
+ COMMAND_UPLOADSERVERCONFIG = 0,
COMMAND_UPLOADLOG,
COMMAND_GM,
COMMAND_HACK,
@@ -74,7 +72,6 @@ enum
static const CommandInfo commands[] =
{
- {"uploadconfig", &Commands::uploadConfig, -1, false},
{"uploadserverconfig", &Commands::uploadServerConfig, -1, false},
{"uploadlog", &Commands::uploadLog, -1, false},
{"gm", &Commands::gm, -1, true},
diff --git a/src/input/inputaction.h b/src/input/inputaction.h
index c7296258d..3dbd37d27 100644
--- a/src/input/inputaction.h
+++ b/src/input/inputaction.h
@@ -418,6 +418,7 @@ namespace InputAction
CREATE_ITEMS,
TALK_RAW,
TALK_PET,
+ UPLOAD_CONFIG,
TOTAL
};
} // namespace InputAction
diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h
index 33d1a3826..5739d8eac 100644
--- a/src/input/inputactionmap.h
+++ b/src/input/inputactionmap.h
@@ -3530,7 +3530,7 @@ static const InputActionData inputActionData[InputAction::TOTAL] = {
InputAction::NO_VALUE, 50,
InputCondition::INGAME,
"talkraw",
- false},
+ true},
{"keyTalkPet",
InputType::UNKNOWN, InputAction::NO_VALUE,
InputType::UNKNOWN, InputAction::NO_VALUE,
@@ -3539,6 +3539,15 @@ static const InputActionData inputActionData[InputAction::TOTAL] = {
InputAction::NO_VALUE, 50,
InputCondition::INGAME,
"talkpet",
+ true},
+ {"keyUploadConfig",
+ InputType::UNKNOWN, InputAction::NO_VALUE,
+ InputType::UNKNOWN, InputAction::NO_VALUE,
+ Input::GRP_DEFAULT,
+ &Actions::uploadConfig,
+ InputAction::NO_VALUE, 50,
+ InputCondition::INGAME,
+ "uploadconfig",
false}
};
diff --git a/src/input/pages/other.cpp b/src/input/pages/other.cpp
index a86d13860..1f6eea0c8 100644
--- a/src/input/pages/other.cpp
+++ b/src/input/pages/other.cpp
@@ -348,6 +348,12 @@ SetupActionData setupActionDataOther[] =
},
#endif
{
+ // TRANSLATORS: input action name
+ N_("Upload main config"),
+ InputAction::UPLOAD_CONFIG,
+ "",
+ },
+ {
"",
InputAction::NO_VALUE,
""