summaryrefslogtreecommitdiff
path: root/src/gui/windows
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-08-25 20:45:38 +0300
committerAndrei Karas <akaras@inbox.ru>2017-08-25 20:45:38 +0300
commitf7d3792df9fd01ea7baabaf9b612031b1f28d7ab (patch)
treea38b12795443c2c364059cf418d6171171d4434b /src/gui/windows
parent6adafcc07e2101ab085bd9f2182c965ef70d0519 (diff)
downloadmv-f7d3792df9fd01ea7baabaf9b612031b1f28d7ab.tar.gz
mv-f7d3792df9fd01ea7baabaf9b612031b1f28d7ab.tar.bz2
mv-f7d3792df9fd01ea7baabaf9b612031b1f28d7ab.tar.xz
mv-f7d3792df9fd01ea7baabaf9b612031b1f28d7ab.zip
Add basic support for view mail message.
Diffstat (limited to 'src/gui/windows')
-rw-r--r--src/gui/windows/mailviewwindow.cpp81
-rw-r--r--src/gui/windows/mailviewwindow.h16
-rw-r--r--src/gui/windows/mailwindow.cpp19
-rw-r--r--src/gui/windows/mailwindow.h8
4 files changed, 76 insertions, 48 deletions
diff --git a/src/gui/windows/mailviewwindow.cpp b/src/gui/windows/mailviewwindow.cpp
index 19d1211bb..d99fd602f 100644
--- a/src/gui/windows/mailviewwindow.cpp
+++ b/src/gui/windows/mailviewwindow.cpp
@@ -21,6 +21,7 @@
#include "gui/windows/mailviewwindow.h"
#include "configuration.h"
+#include "settings.h"
#include "net/mailhandler.h"
@@ -32,8 +33,9 @@
#include "gui/widgets/button.h"
#include "gui/widgets/containerplacer.h"
#include "gui/widgets/createwidget.h"
-#include "gui/widgets/icon.h"
+#include "gui/widgets/itemcontainer.h"
#include "gui/widgets/label.h"
+#include "gui/widgets/scrollarea.h"
#include "utils/delete2.h"
#include "utils/gettext.h"
@@ -42,6 +44,8 @@
#include "resources/image/image.h"
+#include "resources/inventory/inventory.h"
+
#include "resources/loaders/imageloader.h"
#include "resources/db/itemdb.h"
@@ -50,7 +54,8 @@
MailViewWindow *mailViewWindow = nullptr;
-MailViewWindow::MailViewWindow(const MailMessage *const message) :
+MailViewWindow::MailViewWindow(const MailMessage *const message,
+ const int itemsCount) :
// TRANSLATORS: mail view window name
Window(_("View mail"), Modal_false, nullptr, "mailview.xml"),
ActionListener(),
@@ -76,9 +81,12 @@ MailViewWindow::MailViewWindow(const MailMessage *const message) :
// TRANSLATORS: mail view window label
mMessageLabel(new Label(this, strprintf("%s %s", _("Message:"),
message->text.c_str()))),
- // TRANSLATORS: mail view window label
- mItemLabel(nullptr),
- mIcon(nullptr)
+ mInventory(new Inventory(InventoryType::Mail, itemsCount)),
+ mItemContainer(new ItemContainer(this, mInventory)),
+ mItemScrollArea(new ScrollArea(this, mItemContainer,
+ fromBool(getOptionBool("showitemsbackground"), Opaque),
+ "mailedit_listbackground.xml")),
+ mUseMail2(settings.enableNewMailSystem)
{
setWindowName("MailView");
setCloseButton(true);
@@ -91,6 +99,10 @@ MailViewWindow::MailViewWindow(const MailMessage *const message) :
setMinWidth(200);
setMinHeight(100);
center();
+ mItemScrollArea->setHeight(100);
+ mItemScrollArea->setWidth(100);
+
+ mItemScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
ContainerPlacer placer;
placer = getPlacer(0, 0);
@@ -107,35 +119,14 @@ MailViewWindow::MailViewWindow(const MailMessage *const message) :
placer(0, n++, mMoneyLabel);
}
placer(0, n++, mMessageLabel);
- if (message->itemId != 0)
- {
- const ItemInfo &item = ItemDB::get(message->itemId);
- // +++ need use message->cards and ItemColorManager for colors
- Image *const image = Loader::getImage(combineDye2(
- pathJoin(paths.getStringValue("itemIcons"),
- item.getDisplay().image),
- item.getDyeIconColorsString(ItemColor_one)));
-
- mIcon = new Icon(this, image);
- if (message->itemAmount != 1)
- {
- mItemLabel = new Label(this, std::string(
- // TRANSLATORS: mail view item label
- _("Item:")).append(
- " (").append(
- toString(message->itemAmount)).append(
- ") "));
- }
- else
- {
- mItemLabel = new Label(this,
- // TRANSLATORS: mail view item label
- std::string(_("Item:")).append(" "));
- }
- placer(0, n, mItemLabel);
- placer(1, n++, mIcon);
- }
- if ((message->money != 0) || (message->itemId != 0))
+ placer(0, n++, mItemScrollArea);
+
+ logger->log("sizes: %d, %d",
+ mItemContainer->getWidth(),
+ mItemContainer->getHeight());
+
+ if (message->money != 0 ||
+ message->itemId != 0)
{
mGetAttachButton = new Button(this,
// TRANSLATORS: mail view attach button
@@ -158,13 +149,11 @@ MailViewWindow::MailViewWindow(const MailMessage *const message) :
MailViewWindow::~MailViewWindow()
{
- if (mIcon != nullptr)
- {
- Image *const image = mIcon->getImage();
- if (image != nullptr)
- image->decRef();
- }
- delete2(mMessage);
+ if (mUseMail2)
+ mMessage = nullptr;
+ else
+ delete2(mMessage);
+ delete2(mInventory);
mailViewWindow = nullptr;
}
@@ -203,3 +192,13 @@ void MailViewWindow::action(const ActionEvent &event)
scheduleDelete();
}
}
+
+Inventory *MailViewWindow::getInventory() const
+{
+ return mInventory;
+}
+
+void MailViewWindow::updateItems()
+{
+ mItemContainer->updateMatrix();
+}
diff --git a/src/gui/windows/mailviewwindow.h b/src/gui/windows/mailviewwindow.h
index 97cd8e84e..a9d19e57e 100644
--- a/src/gui/windows/mailviewwindow.h
+++ b/src/gui/windows/mailviewwindow.h
@@ -27,7 +27,10 @@
class Button;
class Icon;
+class Inventory;
+class ItemContainer;
class Label;
+class ScrollArea;
struct MailMessage;
@@ -35,7 +38,8 @@ class MailViewWindow final : public Window,
public ActionListener
{
public:
- explicit MailViewWindow(const MailMessage *const message) A_NONNULL(2);
+ MailViewWindow(const MailMessage *const message,
+ const int itemsCount) A_NONNULL(2);
A_DELETE_COPY(MailViewWindow)
@@ -43,6 +47,10 @@ class MailViewWindow final : public Window,
void action(const ActionEvent &event) override final;
+ Inventory *getInventory() const A_WARN_UNUSED;
+
+ void updateItems();
+
private:
const MailMessage *mMessage;
Button *mGetAttachButton;
@@ -55,8 +63,10 @@ class MailViewWindow final : public Window,
Label *mFromLabel;
Label *mSubjectLabel;
Label *mMessageLabel;
- Label *mItemLabel;
- Icon *mIcon;
+ Inventory *mInventory;
+ ItemContainer *mItemContainer;
+ ScrollArea *mItemScrollArea;
+ bool mUseMail2;
};
extern MailViewWindow *mailViewWindow;
diff --git a/src/gui/windows/mailwindow.cpp b/src/gui/windows/mailwindow.cpp
index c12b719fc..8dc54cf94 100644
--- a/src/gui/windows/mailwindow.cpp
+++ b/src/gui/windows/mailwindow.cpp
@@ -140,7 +140,10 @@ void MailWindow::action(const ActionEvent &event)
if (sel < 0)
return;
const MailMessage *const mail = mMessages[sel];
- mailHandler->readMessage(mail->id);
+ if (mUseMail2)
+ mail2Handler->readMail(mOpenType, mail->id);
+ else
+ mailHandler->readMessage(mail->id);
}
else if (eventId == "delete")
{
@@ -234,7 +237,8 @@ void MailWindow::removeMail(const int64_t id)
}
}
-void MailWindow::showMessage(MailMessage *const mail)
+void MailWindow::showMessage(MailMessage *const mail,
+ const int itemsCount)
{
if (mail == nullptr)
return;
@@ -247,7 +251,8 @@ void MailWindow::showMessage(MailMessage *const mail)
mail->strTime = mail2->strTime;
}
delete mailViewWindow;
- CREATEWIDGETV(mailViewWindow, MailViewWindow, mail);
+ CREATEWIDGETV(mailViewWindow, MailViewWindow, mail,
+ itemsCount);
}
void MailWindow::viewNext(const int64_t id)
@@ -337,3 +342,11 @@ void MailWindow::createMail(const std::string &to)
CREATEWIDGETV0(mailEditWindow, MailEditWindow);
mailEditWindow->setTo(to);
}
+
+MailMessage *MailWindow::findMail(const int64_t id)
+{
+ std::map<int64_t, MailMessage*>::iterator it = mMessagesMap.find(id);
+ if (it != mMessagesMap.end())
+ return (*it).second;
+ return nullptr;
+}
diff --git a/src/gui/windows/mailwindow.h b/src/gui/windows/mailwindow.h
index 8a6bc6695..3c38e0329 100644
--- a/src/gui/windows/mailwindow.h
+++ b/src/gui/windows/mailwindow.h
@@ -55,7 +55,8 @@ class MailWindow final : public Window,
void clear() override final;
- void showMessage(MailMessage *const mail);
+ void showMessage(MailMessage *const mail,
+ const int itemsCount);
void removeMail(const int64_t id);
@@ -69,9 +70,14 @@ class MailWindow final : public Window,
void createMail(const std::string &to);
+ MailMessage *findMail(const int64_t id) A_WARN_UNUSED;
+
void setOpenType(const MailOpenTypeT &type)
{ mOpenType = type; }
+ MailOpenTypeT getOpenType() const A_WARN_UNUSED
+ { return mOpenType; }
+
private:
void refreshMails();