summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-08-25 23:55:43 +0300
committerAndrei Karas <akaras@inbox.ru>2017-08-25 23:55:43 +0300
commitd0768817618143739b8fd81cfa9124e8f60e1b12 (patch)
tree94450009f3bf4cd7726250633865f0a112f625fb
parentf7d3792df9fd01ea7baabaf9b612031b1f28d7ab (diff)
downloadplus-d0768817618143739b8fd81cfa9124e8f60e1b12.tar.gz
plus-d0768817618143739b8fd81cfa9124e8f60e1b12.tar.bz2
plus-d0768817618143739b8fd81cfa9124e8f60e1b12.tar.xz
plus-d0768817618143739b8fd81cfa9124e8f60e1b12.zip
Validate destination name after it entered in mail edit window.
-rw-r--r--src/enums/resources/mailqueuetype.h2
-rw-r--r--src/gui/windows/maileditwindow.cpp34
-rw-r--r--src/gui/windows/maileditwindow.h8
-rw-r--r--src/net/eathena/mail2handler.cpp7
-rw-r--r--src/net/eathena/mail2handler.h2
-rw-r--r--src/net/eathena/mail2recv.cpp22
-rw-r--r--src/net/eathena/mail2recv.h1
-rw-r--r--src/net/mail2handler.h2
-rw-r--r--src/net/tmwa/mail2handler.cpp5
-rw-r--r--src/net/tmwa/mail2handler.h2
10 files changed, 80 insertions, 5 deletions
diff --git a/src/enums/resources/mailqueuetype.h b/src/enums/resources/mailqueuetype.h
index c4fb6162f..bb953f37e 100644
--- a/src/enums/resources/mailqueuetype.h
+++ b/src/enums/resources/mailqueuetype.h
@@ -28,7 +28,7 @@ enumStart(MailQueueType)
Unknown = 0,
SendMail = 1,
EditMail = 2,
- ValidateTO = 3
+ ValidateTo = 3
}
enumEnd(MailQueueType);
diff --git a/src/gui/windows/maileditwindow.cpp b/src/gui/windows/maileditwindow.cpp
index 47b4d409e..b3cfd560b 100644
--- a/src/gui/windows/maileditwindow.cpp
+++ b/src/gui/windows/maileditwindow.cpp
@@ -52,6 +52,7 @@ MailEditWindow::MailEditWindow() :
// TRANSLATORS: mail edit window name
Window(_("Edit mail"), Modal_false, nullptr, "mailedit.xml"),
ActionListener(),
+ FocusListener(),
// TRANSLATORS: mail edit window button
mSendButton(new Button(this, _("Send"), "send", this)),
// TRANSLATORS: mail edit window button
@@ -101,8 +102,8 @@ MailEditWindow::MailEditWindow() :
mSubjectField->setWidth(100);
mMessageField->setWidth(100);
mItemScrollArea->setHeight(100);
-
mItemScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
+ mToField->addFocusListener(this);
placer(0, 0, mToLabel);
placer(1, 0, mToField, 3);
@@ -120,6 +121,7 @@ MailEditWindow::MailEditWindow() :
placer(3, 6, mCloseButton);
loadWindowState();
+ mSendButton->setEnabled(false);
enableVisibleSound(true);
}
@@ -177,6 +179,7 @@ void MailEditWindow::setSubject(const std::string &str)
void MailEditWindow::setTo(const std::string &str)
{
mToField->setText(str);
+ mSendButton->setEnabled(true);
}
void MailEditWindow::setMessage(const std::string &str)
@@ -240,3 +243,32 @@ void MailEditWindow::updateItems()
{
mItemContainer->updateMatrix();
}
+
+void MailEditWindow::focusLost(const Event &event)
+{
+ if (!mUseMail2)
+ return;
+
+ if (event.getSource() == mToField)
+ {
+ const std::string to = mToField->getText();
+ if (to != mail2Handler->getCheckedName())
+ {
+ mail2Handler->queueCheckName(MailQueueType::ValidateTo,
+ to,
+ std::string(),
+ std::string(),
+ 0);
+ mSendButton->setEnabled(false);
+ }
+ else
+ {
+ mSendButton->setEnabled(true);
+ }
+ }
+}
+
+void MailEditWindow::validatedTo()
+{
+ mSendButton->setEnabled(true);
+}
diff --git a/src/gui/windows/maileditwindow.h b/src/gui/windows/maileditwindow.h
index 37d983c1c..2c6c5d0ef 100644
--- a/src/gui/windows/maileditwindow.h
+++ b/src/gui/windows/maileditwindow.h
@@ -24,6 +24,7 @@
#include "gui/widgets/window.h"
#include "listeners/actionlistener.h"
+#include "listeners/focuslistener.h"
class Button;
class IntTextField;
@@ -35,7 +36,8 @@ class ScrollArea;
class TextField;
class MailEditWindow final : public Window,
- public ActionListener
+ public ActionListener,
+ public FocusListener
{
public:
MailEditWindow();
@@ -60,6 +62,10 @@ class MailEditWindow final : public Window,
void updateItems();
+ void focusLost(const Event &event) override final;
+
+ void validatedTo();
+
private:
void sendMail();
diff --git a/src/net/eathena/mail2handler.cpp b/src/net/eathena/mail2handler.cpp
index bc749b0bf..ae48fc3ed 100644
--- a/src/net/eathena/mail2handler.cpp
+++ b/src/net/eathena/mail2handler.cpp
@@ -49,6 +49,7 @@ Mail2Handler::Mail2Handler()
Mail2Handler::~Mail2Handler()
{
mail2Handler = nullptr;
+ Mail2Recv::mCheckedName.clear();
while (!Mail2Recv::mMailQueue.empty())
{
MailQueue *const mail = Mail2Recv::mMailQueue.front();
@@ -135,6 +136,7 @@ void Mail2Handler::sendMail(const std::string &to,
outMsg.writeInt32(0, "to char id");
outMsg.writeString(title, titleSz, "title");
outMsg.writeString(body, bodySz, "body");
+ Mail2Recv::mCheckedName.clear();
}
void Mail2Handler::queueCheckName(const MailQueueTypeT type,
@@ -274,4 +276,9 @@ void Mail2Handler::requestCheckName(const std::string &name) const
outMsg.writeString(name, 24, "name");
}
+std::string Mail2Handler::getCheckedName() const
+{
+ return Mail2Recv::mCheckedName;
+}
+
} // namespace EAthena
diff --git a/src/net/eathena/mail2handler.h b/src/net/eathena/mail2handler.h
index f6f217579..c7d15dc78 100644
--- a/src/net/eathena/mail2handler.h
+++ b/src/net/eathena/mail2handler.h
@@ -79,6 +79,8 @@ class Mail2Handler final : public Net::Mail2Handler
void cancelWriteMail() const override final;
void requestCheckName(const std::string &name) const override final;
+
+ std::string getCheckedName() const override final;
};
} // namespace EAthena
diff --git a/src/net/eathena/mail2recv.cpp b/src/net/eathena/mail2recv.cpp
index 3da4ae4c5..fe36172b9 100644
--- a/src/net/eathena/mail2recv.cpp
+++ b/src/net/eathena/mail2recv.cpp
@@ -63,6 +63,7 @@ namespace EAthena
namespace Mail2Recv
{
std::queue<MailQueue*> mMailQueue;
+ std::string mCheckedName;
} // namespace Mail2Recv
void Mail2Recv::processMailIcon(Net::MessageIn &msg)
@@ -255,6 +256,7 @@ void Mail2Recv::processCheckNameResult(Net::MessageIn &msg)
delete mail;
return;
}
+ mCheckedName = mail->to;
switch (mail->type)
{
case MailQueueType::SendMail:
@@ -264,10 +266,26 @@ void Mail2Recv::processCheckNameResult(Net::MessageIn &msg)
mail->money);
break;
case MailQueueType::EditMail:
- mailWindow->createMail(mail->to);
+ if (mailWindow == nullptr)
+ {
+ reportAlways("Mail window not created");
+ }
+ else
+ {
+ mailWindow->createMail(mail->to);
+ }
+ break;
+ case MailQueueType::ValidateTo:
+ if (mailEditWindow == nullptr)
+ {
+ reportAlways("Mail edit window not created");
+ }
+ else
+ {
+ mailEditWindow->validatedTo();
+ }
break;
case MailQueueType::Unknown:
- case MailQueueType::ValidateTO:
default:
reportAlways("Not implemented yet.");
break;
diff --git a/src/net/eathena/mail2recv.h b/src/net/eathena/mail2recv.h
index dd867618e..dc575b0c8 100644
--- a/src/net/eathena/mail2recv.h
+++ b/src/net/eathena/mail2recv.h
@@ -35,6 +35,7 @@ namespace EAthena
namespace Mail2Recv
{
extern std::queue<MailQueue*> mMailQueue;
+ extern std::string mCheckedName;
void processMailIcon(Net::MessageIn &msg);
void processOpenNewMailWindow(Net::MessageIn &msg);
diff --git a/src/net/mail2handler.h b/src/net/mail2handler.h
index 56ad516cd..55c238b46 100644
--- a/src/net/mail2handler.h
+++ b/src/net/mail2handler.h
@@ -89,6 +89,8 @@ class Mail2Handler notfinal
virtual void cancelWriteMail() const = 0;
virtual void requestCheckName(const std::string &name) const = 0;
+
+ virtual std::string getCheckedName() const = 0;
};
} // namespace Net
diff --git a/src/net/tmwa/mail2handler.cpp b/src/net/tmwa/mail2handler.cpp
index 70a8cfda5..786a31a6f 100644
--- a/src/net/tmwa/mail2handler.cpp
+++ b/src/net/tmwa/mail2handler.cpp
@@ -110,4 +110,9 @@ void Mail2Handler::requestCheckName(const std::string &name A_UNUSED) const
{
}
+std::string Mail2Handler::getCheckedName() const
+{
+ return std::string();
+}
+
} // namespace TmwAthena
diff --git a/src/net/tmwa/mail2handler.h b/src/net/tmwa/mail2handler.h
index 221e714b5..003a29b89 100644
--- a/src/net/tmwa/mail2handler.h
+++ b/src/net/tmwa/mail2handler.h
@@ -79,6 +79,8 @@ class Mail2Handler final : public Net::Mail2Handler
void cancelWriteMail() const override final;
void requestCheckName(const std::string &name) const override final;
+
+ std::string getCheckedName() const override final;
};
} // namespace TmwAthena