summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-08-25 03:10:19 +0300
committerAndrei Karas <akaras@inbox.ru>2017-08-25 03:10:19 +0300
commitb68c40d34eecf9da09a00101286b046d93927161 (patch)
tree3a72009efde8295d85309b77abe1df9b5e9d5ec7
parent82e3927dd6a1e7c035cda8c88a1287834367b95f (diff)
downloadmv-b68c40d34eecf9da09a00101286b046d93927161.tar.gz
mv-b68c40d34eecf9da09a00101286b046d93927161.tar.bz2
mv-b68c40d34eecf9da09a00101286b046d93927161.tar.xz
mv-b68c40d34eecf9da09a00101286b046d93927161.zip
Add support for show mail list for new mail system.
-rw-r--r--src/gui/mailmessage.h8
-rw-r--r--src/gui/windows/mailwindow.cpp38
-rw-r--r--src/gui/windows/mailwindow.h8
-rw-r--r--src/net/eathena/mail2recv.cpp29
-rw-r--r--src/net/eathena/mailrecv.cpp2
5 files changed, 64 insertions, 21 deletions
diff --git a/src/gui/mailmessage.h b/src/gui/mailmessage.h
index c7aaf1cc7..b5ce75612 100644
--- a/src/gui/mailmessage.h
+++ b/src/gui/mailmessage.h
@@ -36,13 +36,15 @@ struct MailMessage final
text(),
id(0),
time(0),
+ expireTime(0),
money(0),
itemAmount(0),
itemId(0),
itemType(0),
itemAttribute(0U),
itemRefine(0U),
- unread(false),
+ type(0U),
+ read(false),
itemIdentify(false)
{
for (int f = 0; f < 4; f ++)
@@ -58,13 +60,15 @@ struct MailMessage final
uint16_t card[maxMailCards];
int id;
int time;
+ int expireTime;
int money;
int itemAmount;
int itemId;
int itemType;
uint8_t itemAttribute;
uint8_t itemRefine;
- bool unread;
+ uint8_t type;
+ bool read;
bool itemIdentify;
};
#endif // GUI_MAILMESSAGE_H
diff --git a/src/gui/windows/mailwindow.cpp b/src/gui/windows/mailwindow.cpp
index 3d157ad3b..ec107f3a6 100644
--- a/src/gui/windows/mailwindow.cpp
+++ b/src/gui/windows/mailwindow.cpp
@@ -46,6 +46,7 @@
#include "utils/dtor.h"
#include "utils/foreach.h"
#include "utils/gettext.h"
+#include "utils/stdmove.h"
#include "utils/stringutils.h"
#include "debug.h"
@@ -60,7 +61,7 @@ MailWindow::MailWindow() :
mMessagesMap(),
mMailModel(new ExtendedNamesModel),
mListBox(CREATEWIDGETR(ExtendedListBox,
- this, mMailModel, "extendedlistbox.xml")),
+ this, mMailModel, "extendedlistbox.xml", 0)),
mListScrollArea(new ScrollArea(this, mListBox,
fromBool(getOptionBool("showlistbackground"), Opaque),
"mail_listbackground.xml")),
@@ -74,6 +75,7 @@ MailWindow::MailWindow() :
mReturnButton(new Button(this, _("Return"), "return", this)),
// TRANSLATORS: mail window button
mOpenButton(new Button(this, _("Open"), "open", this)),
+ mOpenType(MailOpenType::Mail),
mUseMail2(settings.enableNewMailSystem)
{
setWindowName("Mail");
@@ -167,14 +169,31 @@ void MailWindow::clear()
mListBox->setSelected(-1);
}
+std::string MailWindow::getMailHeader(MailMessage *const message)
+{
+ if (mUseMail2)
+ {
+ std::string header;
+ if (message->read)
+ header.append(" ");
+ else
+ header.append("U");
+ return STD_MOVE(header);
+ }
+ else
+ {
+ return strprintf("%s %s",
+ message->read ? " " : "U",
+ message->title.c_str());
+ }
+}
+
void MailWindow::addMail(MailMessage *const message)
{
if (message == nullptr)
return;
mMessages.push_back(message);
- mMailModel->add(strprintf("%s %s",
- message->unread ? " " : "U",
- message->title.c_str()));
+ mMailModel->add(getMailHeader(message));
mMessagesMap[message->id] = message;
}
@@ -201,11 +220,7 @@ void MailWindow::removeMail(const int id)
{
MailMessage *message = *it;
if (message != nullptr)
- {
- mMailModel->add(strprintf("%s %s",
- message->unread ? " " : "U",
- message->title.c_str()));
- }
+ mMailModel->add(getMailHeader(message));
}
}
@@ -294,9 +309,14 @@ void MailWindow::postConnection()
void MailWindow::refreshMails()
{
if (mUseMail2)
+ {
+ clear();
mail2Handler->refreshMailList(MailOpenType::Mail, 0);
+ }
else
+ {
mailHandler->refresh();
+ }
}
void MailWindow::createMail(const std::string &to)
diff --git a/src/gui/windows/mailwindow.h b/src/gui/windows/mailwindow.h
index 9ac4a5069..b356b0666 100644
--- a/src/gui/windows/mailwindow.h
+++ b/src/gui/windows/mailwindow.h
@@ -23,6 +23,8 @@
#include "gui/widgets/window.h"
+#include "enums/net/mailopentype.h"
+
#include "listeners/actionlistener.h"
class Button;
@@ -67,9 +69,14 @@ class MailWindow final : public Window,
void createMail(const std::string &to);
+ void setOpenType(const MailOpenTypeT &type)
+ { mOpenType = type; }
+
private:
void refreshMails();
+ std::string getMailHeader(MailMessage *const message) A_NONNULL(2);
+
STD_VECTOR<MailMessage*> mMessages;
std::map<int, MailMessage*> mMessagesMap;
ExtendedNamesModel *mMailModel;
@@ -80,6 +87,7 @@ class MailWindow final : public Window,
Button *mDeleteButton;
Button *mReturnButton;
Button *mOpenButton;
+ MailOpenTypeT mOpenType;
bool mUseMail2;
};
diff --git a/src/net/eathena/mail2recv.cpp b/src/net/eathena/mail2recv.cpp
index 3b6b7ed1a..eb4c8d6b6 100644
--- a/src/net/eathena/mail2recv.cpp
+++ b/src/net/eathena/mail2recv.cpp
@@ -32,6 +32,8 @@
#include "enums/resources/notifytypes.h"
+#include "gui/mailmessage.h"
+
#include "gui/windows/maileditwindow.h"
#include "gui/windows/mailwindow.h"
@@ -50,6 +52,7 @@
#include "utils/checkutils.h"
#include "utils/gettext.h"
+#include "utils/stringutils.h"
#include "debug.h"
@@ -279,20 +282,28 @@ void Mail2Recv::processSendResult(Net::MessageIn &msg)
void Mail2Recv::processMailListPage(Net::MessageIn &msg)
{
- UNIMPLEMENTEDPACKET;
+ if (mailWindow == nullptr)
+ {
+ reportAlways("mail window not created");
+ return;
+ }
msg.readInt16("len");
- msg.readUInt8("open type");
+ mailWindow->setOpenType(fromInt(msg.readUInt8("open type"),
+ MailOpenTypeT));
const int cnt = msg.readUInt8("cnt");
msg.readUInt8("isEnd");
for (int f = 0; f < cnt; f ++)
{
- msg.readInt64("mail id");
- msg.readUInt8("is read");
- msg.readUInt8("type");
- msg.readString(24, "sender name");
- msg.readInt32("reg time");
- msg.readInt32("expire time");
- msg.readString(-1, "title");
+ MailMessage *const mail = new MailMessage;
+ mail->id = msg.readInt64("mail id");
+ mail->read = msg.readUInt8("is read") != 0U ? true : false;
+ mail->type = msg.readUInt8("type");
+ mail->sender = msg.readString(24, "sender name");
+ mail->time = msg.readInt32("reg time");
+ mail->strTime = timeToStr(mail->time);
+ mail->expireTime = msg.readInt32("expire time");
+ mail->title = msg.readString(-1, "title");
+ mailWindow->addMail(mail);
}
}
diff --git a/src/net/eathena/mailrecv.cpp b/src/net/eathena/mailrecv.cpp
index c098b6857..93a548c69 100644
--- a/src/net/eathena/mailrecv.cpp
+++ b/src/net/eathena/mailrecv.cpp
@@ -79,7 +79,7 @@ void MailRecv::processMailList(Net::MessageIn &msg)
MailMessage *const mail = new MailMessage;
mail->id = msg.readInt32("message id");
mail->title = msg.readString(40, "title");
- mail->unread = msg.readUInt8("unread flag") != 0u ? true : false;
+ mail->read = msg.readUInt8("unread flag") != 0u ? true : false;
mail->sender = msg.readString(24, "sender name");
mail->time = msg.readInt32("time stamp");
mail->strTime = timeToStr(mail->time);