diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-04-29 14:01:37 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-04-29 14:10:28 +0300 |
commit | f820365eed7e956e67e6122a8a5ab529e7df9474 (patch) | |
tree | 9ee43bae2f7cafa38ab0cf018b8dbaf49d531f38 /src/gui | |
parent | 4b0f30b1e1879cee6d65394d826bba21eca6c40b (diff) | |
download | manaplus-f820365eed7e956e67e6122a8a5ab529e7df9474.tar.gz manaplus-f820365eed7e956e67e6122a8a5ab529e7df9474.tar.bz2 manaplus-f820365eed7e956e67e6122a8a5ab529e7df9474.tar.xz manaplus-f820365eed7e956e67e6122a8a5ab529e7df9474.zip |
Fix time in mail view window.
Also fix possible leaks in mail windows.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/windows/mailedit.cpp | 3 | ||||
-rw-r--r-- | src/gui/windows/mailview.cpp | 23 | ||||
-rw-r--r-- | src/gui/windows/mailview.h | 3 | ||||
-rw-r--r-- | src/gui/windows/mailwindow.cpp | 22 | ||||
-rw-r--r-- | src/gui/windows/mailwindow.h | 3 |
5 files changed, 42 insertions, 12 deletions
diff --git a/src/gui/windows/mailedit.cpp b/src/gui/windows/mailedit.cpp index ba3972992..5bb669b72 100644 --- a/src/gui/windows/mailedit.cpp +++ b/src/gui/windows/mailedit.cpp @@ -40,6 +40,7 @@ #include "gui/widgets/scrollarea.h" #include "gui/widgets/textfield.h" +#include "utils/delete2.h" #include "utils/gettext.h" #include "utils/stringutils.h" @@ -106,7 +107,6 @@ MailEdit::MailEdit() : placer(1, 1, mSubjectField, 3); placer(0, 2, mMoneyLabel); placer(1, 2, mMoneyField, 3); -// placer(0, 3, mItemScrollArea, 3); placer(0, 3, mItemLabel); placer(1, 3, mItemScrollArea, 2, 2); placer(3, 4, mAddButton, 1); @@ -123,6 +123,7 @@ MailEdit::MailEdit() : MailEdit::~MailEdit() { mailEditWindow = nullptr; + delete2(mInventory); } void MailEdit::action(const ActionEvent &event) diff --git a/src/gui/windows/mailview.cpp b/src/gui/windows/mailview.cpp index 4c252c89d..32a207acf 100644 --- a/src/gui/windows/mailview.cpp +++ b/src/gui/windows/mailview.cpp @@ -36,6 +36,7 @@ #include "gui/widgets/layouttype.h" #include "gui/widgets/textfield.h" +#include "utils/delete2.h" #include "utils/gettext.h" #include "utils/stringutils.h" @@ -47,9 +48,11 @@ #include "debug.h" +MailView *mailViewWindow = nullptr; + MailView::MailView(const MailMessage *const message) : // TRANSLATORS: mail view window name - Window(_("View mail"), true, nullptr, "mailview.xml"), + Window(_("View mail"), false, nullptr, "mailview.xml"), ActionListener(), mMessage(message), // TRANSLATORS: mail view window button @@ -70,9 +73,8 @@ MailView::MailView(const MailMessage *const message) : mMessageLabel(new Label(this, strprintf("%s %s", _("Message:"), message->text.c_str()))), // TRANSLATORS: mail view window label - mItemLabel(new Label(this, std::string(_("Item:")).append(" "))), - mMessageField(new TextField(this)), - mIcon(new Icon(this, nullptr)) + mItemLabel(nullptr), + mIcon(nullptr) { setWindowName("MailView"); setCloseButton(true); @@ -89,8 +91,6 @@ MailView::MailView(const MailMessage *const message) : ContainerPlacer placer; placer = getPlacer(0, 0); - mMessageField->setWidth(100); - int n = 0; placer(0, n++, mTimeLabel); placer(0, n++, mFromLabel); @@ -111,7 +111,8 @@ MailView::MailView(const MailMessage *const message) : paths.getStringValue("itemIcons").append( item.getDisplay().image), item.getDyeColorsString(1))); - mIcon->setImage(image); + mIcon = new Icon(this, image); + mItemLabel = new Label(this, std::string(_("Item:")).append(" ")); placer(0, n, mItemLabel); placer(1, n++, mIcon); } @@ -125,6 +126,14 @@ MailView::MailView(const MailMessage *const message) : MailView::~MailView() { + if (mIcon) + { + Image *const image = mIcon->getImage(); + if (image) + image->decRef(); + } + delete2(mMessage); + mailViewWindow = nullptr; } void MailView::action(const ActionEvent &event) diff --git a/src/gui/windows/mailview.h b/src/gui/windows/mailview.h index 803dbc3d5..8d1ddde78 100644 --- a/src/gui/windows/mailview.h +++ b/src/gui/windows/mailview.h @@ -56,9 +56,10 @@ class MailView final : public Window, Label *mSubjectLabel; Label *mMessageLabel; Label *mItemLabel; - TextField *mMessageField; Icon *mIcon; }; +extern MailView *mailViewWindow; + #endif // EATHENA_SUPPORT #endif // GUI_WINDOWS_MAILVIEW_H diff --git a/src/gui/windows/mailwindow.cpp b/src/gui/windows/mailwindow.cpp index ef6444405..1d0bbca62 100644 --- a/src/gui/windows/mailwindow.cpp +++ b/src/gui/windows/mailwindow.cpp @@ -51,6 +51,7 @@ MailWindow::MailWindow() : Window(_("Mail"), false, nullptr, "mail.xml"), ActionListener(), mMessages(), + mMessagesMap(), mMailModel(new ExtendedNamesModel), mListBox(new ExtendedListBox(this, mMailModel, "extendedlistbox.xml")), // TRANSLATORS: mail window button @@ -98,6 +99,8 @@ MailWindow::~MailWindow() { delete_all(mMessages); delete2(mMailModel); + delete2(mailViewWindow); + delete2(mailEditWindow); } void MailWindow::action(const ActionEvent &event) @@ -126,19 +129,34 @@ void MailWindow::clear() { delete_all(mMessages); mMessages.clear(); + mMessagesMap.clear(); mMailModel->clear(); mListBox->setSelected(-1); } void MailWindow::addMail(MailMessage *const message) { + if (!message) + return; mMessages.push_back(message); mMailModel->add(strprintf("%s %s", message->unread ? " " : "U", message->title.c_str())); + mMessagesMap[message->id] = message; } -void MailWindow::showMessage(const MailMessage *const mail) +void MailWindow::showMessage(MailMessage *const mail) { - new MailView(mail); + if (!mail) + return; + const std::map<int, MailMessage*>::const_iterator + it = mMessagesMap.find(mail->id); + if (it != mMessagesMap.end()) + { + const MailMessage *const mail2 = (*it).second; + mail->time = mail2->time; + mail->strTime = mail2->strTime; + } + delete mailViewWindow; + mailViewWindow = new MailView(mail); } diff --git a/src/gui/windows/mailwindow.h b/src/gui/windows/mailwindow.h index b92b21d9e..236b3c7e1 100644 --- a/src/gui/windows/mailwindow.h +++ b/src/gui/windows/mailwindow.h @@ -54,10 +54,11 @@ class MailWindow final : public Window, void clear(); - void showMessage(const MailMessage *const mail); + void showMessage(MailMessage *const mail); private: std::vector<MailMessage*> mMessages; + std::map<int, MailMessage*> mMessagesMap; ExtendedNamesModel *mMailModel; ExtendedListBox *mListBox; Button *mRefreshButton; |