diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-04-27 18:20:50 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-04-27 19:55:54 +0300 |
commit | 9af27292809ee8bf42f46e214c21c305c3cd810f (patch) | |
tree | 99a6ba2d4943932742255ba05eba1a0a94305754 /src | |
parent | 22ba86a17c2a7ce05cad3cdd1713081a6ea1b2fe (diff) | |
download | manaplus-9af27292809ee8bf42f46e214c21c305c3cd810f.tar.gz manaplus-9af27292809ee8bf42f46e214c21c305c3cd810f.tar.bz2 manaplus-9af27292809ee8bf42f46e214c21c305c3cd810f.tar.xz manaplus-9af27292809ee8bf42f46e214c21c305c3cd810f.zip |
eathena: impliment packet SMSG_MAIL_MAILS_LIST.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/windows/mailwindow.cpp | 20 | ||||
-rw-r--r-- | src/gui/windows/mailwindow.h | 7 | ||||
-rw-r--r-- | src/net/eathena/mailhandler.cpp | 19 |
3 files changed, 39 insertions, 7 deletions
diff --git a/src/gui/windows/mailwindow.cpp b/src/gui/windows/mailwindow.cpp index 873242e5d..966077e93 100644 --- a/src/gui/windows/mailwindow.cpp +++ b/src/gui/windows/mailwindow.cpp @@ -24,6 +24,8 @@ #include "gui/models/extendednamesmodel.h" +#include "gui/mailmessage.h" + #include "gui/windows/mailedit.h" #include "gui/windows/setupwindow.h" @@ -34,6 +36,8 @@ #include "gui/widgets/layout.h" #include "gui/widgets/layouttype.h" +#include "utils/delete2.h" +#include "utils/dtor.h" #include "utils/gettext.h" #include "utils/stringutils.h" @@ -45,6 +49,7 @@ MailWindow::MailWindow() : // TRANSLATORS: mail window name Window(_("Mail"), false, nullptr, "mail.xml"), ActionListener(), + mMessages(), mMailModel(new ExtendedNamesModel), mListBox(new ExtendedListBox(this, mMailModel, "extendedlistbox.xml")), // TRANSLATORS: mail window button @@ -90,6 +95,8 @@ MailWindow::MailWindow() : MailWindow::~MailWindow() { + delete_all(mMessages); + delete2(mMailModel); } void MailWindow::action(const ActionEvent &event) @@ -104,3 +111,16 @@ void MailWindow::action(const ActionEvent &event) new MailEdit(); } } + +void MailWindow::clear() +{ + delete_all(mMessages); + mMailModel->clear(); + mListBox->setSelected(-1); +} + +void MailWindow::addMail(MailMessage *const message) +{ + mMessages.push_back(message); + mMailModel->add(message->title); +} diff --git a/src/gui/windows/mailwindow.h b/src/gui/windows/mailwindow.h index 5bab5bbd7..459a6ffc7 100644 --- a/src/gui/windows/mailwindow.h +++ b/src/gui/windows/mailwindow.h @@ -31,6 +31,8 @@ class Button; class ExtendedListBox; class ExtendedNamesModel; +struct MailMessage; + /** * A dialog to choose between buying or selling at a shop. * @@ -48,7 +50,12 @@ class MailWindow final : public Window, void action(const ActionEvent &event) override final; + void addMail(MailMessage *const message); + + void clear(); + private: + std::vector<MailMessage*> mMessages; ExtendedNamesModel *mMailModel; ExtendedListBox *mListBox; Button *mRefreshButton; diff --git a/src/net/eathena/mailhandler.cpp b/src/net/eathena/mailhandler.cpp index c8fdff4b2..7d7e128ce 100644 --- a/src/net/eathena/mailhandler.cpp +++ b/src/net/eathena/mailhandler.cpp @@ -22,6 +22,10 @@ #include "logger.h" +#include "gui/mailmessage.h" + +#include "gui/windows/mailwindow.h" + #include "net/ea/eaprotocol.h" #include "net/eathena/messageout.h" @@ -119,19 +123,20 @@ void MailHandler::processMailOpen(Net::MessageIn &msg) void MailHandler::processMailList(Net::MessageIn &msg) { - UNIMPLIMENTEDPACKET; - const int count = (msg.readInt16("len") - 8) / 73; const int amount = msg.readInt32("amount"); if (count != amount) logger->log("error: wrong mails count"); + mailWindow->clear(); for (int f = 0; f < count; f ++) { - msg.readInt32("message id"); - msg.readString(40, "title"); - msg.readUInt8("unread flag"); - msg.readString(24, "sender name"); - msg.readInt32("time stamp"); + MailMessage *const mail = new MailMessage; + mail->id = msg.readInt32("message id"); + mail->title = msg.readString(40, "title"); + mail->unread = msg.readUInt8("unread flag") ? true : false; + mail->sender = msg.readString(24, "sender name"); + mail->time = msg.readInt32("time stamp"); + mailWindow->addMail(mail); } } |