diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-08-24 18:50:33 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-08-24 18:50:33 +0300 |
commit | b1a5cce09fc03bf5d4ffbd36ffd24ac59675b41f (patch) | |
tree | 0a3bf5eacbfa33042a07e6d85d8cc0e15ce40d12 | |
parent | 3c7ec1268f2699884a5d96aa1df20742457caabd (diff) | |
download | plus-b1a5cce09fc03bf5d4ffbd36ffd24ac59675b41f.tar.gz plus-b1a5cce09fc03bf5d4ffbd36ffd24ac59675b41f.tar.bz2 plus-b1a5cce09fc03bf5d4ffbd36ffd24ac59675b41f.tar.xz plus-b1a5cce09fc03bf5d4ffbd36ffd24ac59675b41f.zip |
Add sending mail to new mail system.
-rw-r--r-- | src/gui/windows/maileditwindow.cpp | 77 | ||||
-rw-r--r-- | src/gui/windows/maileditwindow.h | 2 |
2 files changed, 50 insertions, 29 deletions
diff --git a/src/gui/windows/maileditwindow.cpp b/src/gui/windows/maileditwindow.cpp index fb805e105..45e61a948 100644 --- a/src/gui/windows/maileditwindow.cpp +++ b/src/gui/windows/maileditwindow.cpp @@ -36,11 +36,14 @@ #include "resources/item/item.h" +#include "net/mail2handler.h" #include "net/mailhandler.h" #include "utils/delete2.h" #include "utils/gettext.h" +#include <climits> + #include "debug.h" MailEditWindow *mailEditWindow = nullptr; @@ -67,7 +70,8 @@ MailEditWindow::MailEditWindow() : mMessageLabel(new Label(this, _("Message:"))), mToField(new TextField(this)), mSubjectField(new TextField(this)), - mMoneyField(new IntTextField(this, 0, 0, 10000000)), + mMoneyField(new IntTextField(this, 0, 0, + settings.enableNewMailSystem ? INT_MAX : 10000000)), mMessageField(new TextField(this)), mInventory(new Inventory(InventoryType::Mail, settings.enableNewMailSystem ? -1 : 1)), @@ -135,34 +139,7 @@ void MailEditWindow::action(const ActionEvent &event) } else if (eventId == "send") { - const int money = mMoneyField->getValue(); - if (money != 0) - mailHandler->setAttachMoney(money); - const Item *const tempItem = mInventory->getItem(0); - if (tempItem != nullptr) - { - const Inventory *const inv = PlayerInfo::getInventory(); - if (inv != nullptr) - { - const Item *const item = inv->findItem( - tempItem->getId(), ItemColor_one); - if (item != nullptr) - { - mailHandler->setAttach(item->getInvIndex(), - tempItem->getQuantity()); - } - } - } - - std::string subject = mSubjectField->getText(); - if (subject.empty()) - { - // TRANSLATORS: empty mail message subject - subject.append(_("empty subject")); - } - mailHandler->send(mToField->getText(), - subject, - mMessageField->getText()); + sendMail(); } else if (eventId == "add") { @@ -217,3 +194,45 @@ Inventory *MailEditWindow::getInventory() const { return mInventory; } + +void MailEditWindow::sendMail() +{ + const int money = mMoneyField->getValue(); + std::string subject = mSubjectField->getText(); + if (subject.empty()) + { + // TRANSLATORS: empty mail message subject + subject.append(_("empty subject")); + } + if (mUseMail2) + { + mail2Handler->sendMail(mToField->getText(), + subject, + mMessageField->getText(), + money); + } + else + { + if (money != 0) + mailHandler->setAttachMoney(money); + const Item *const tempItem = mInventory->getItem(0); + if (tempItem != nullptr) + { + const Inventory *const inv = PlayerInfo::getInventory(); + if (inv != nullptr) + { + const Item *const item = inv->findItem( + tempItem->getId(), ItemColor_one); + if (item != nullptr) + { + mailHandler->setAttach(item->getInvIndex(), + tempItem->getQuantity()); + } + } + } + + mailHandler->send(mToField->getText(), + subject, + mMessageField->getText()); + } +} diff --git a/src/gui/windows/maileditwindow.h b/src/gui/windows/maileditwindow.h index a7d921f8d..031a1545d 100644 --- a/src/gui/windows/maileditwindow.h +++ b/src/gui/windows/maileditwindow.h @@ -59,6 +59,8 @@ class MailEditWindow final : public Window, Inventory *getInventory() const A_WARN_UNUSED; private: + void sendMail(); + Button *mSendButton; Button *mCloseButton; Button *mAddButton; |