GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/bankwindow.cpp Lines: 27 40 67.5 %
Date: 2017-11-29 Branches: 34 80 42.5 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2017  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "gui/windows/bankwindow.h"
22
23
#include "net/bankhandler.h"
24
25
#include "gui/windows/setupwindow.h"
26
27
#include "gui/widgets/button.h"
28
#include "gui/widgets/containerplacer.h"
29
#include "gui/widgets/inttextfield.h"
30
#include "gui/widgets/label.h"
31
32
#include "utils/gettext.h"
33
#include "utils/stringutils.h"
34
35
#include "resources/db/unitsdb.h"
36
37
#include "debug.h"
38
39
BankWindow *bankWindow = nullptr;
40
41
2
BankWindow::BankWindow() :
42
    // TRANSLATORS: bank window name
43
2
    Window(_("Bank"), Modal_false, nullptr, "bank.xml"),
44
    ActionListener(),
45
    BankListener(),
46
4
    mBankMoneyLabel(new Label(this, strprintf(
47
        // TRANSLATORS: bank window money label
48

4
        _("Money in bank: %s"), "            "))),
49

2
    mInputMoneyTextField(new IntTextField(this, 0, 0, 2147483647)),
50
    // TRANSLATORS: bank window button
51

4
    mWithdrawButton(new Button(this, _("Withdraw"), "withdraw", this)),
52
    // TRANSLATORS: bank window button
53





46
    mDepositButton(new Button(this, _("Deposit"), "deposit", this))
54
{
55
10
    setWindowName("Bank");
56
2
    setCloseButton(true);
57
58
2
    if (setupWindow != nullptr)
59
        setupWindow->registerWindowForReset(this);
60
61
2
    mBankMoneyLabel->adjustSize();
62
2
    ContainerPlacer placer = getPlacer(0, 0);
63
2
    placer(0, 0, mBankMoneyLabel, 7);
64
2
    placer(0, 1, mInputMoneyTextField, 10);
65
2
    placer(0, 2, mDepositButton, 5);
66
2
    placer(5, 2, mWithdrawButton, 5);
67
68
2
    setContentSize(300, 100);
69
2
    setDefaultSize(300, 100, ImagePosition::CENTER, 0, 0);
70
71
2
    center();
72
2
    setDefaultSize();
73
2
    loadWindowState();
74
2
    reflowLayout(300);
75
4
    enableVisibleSound(true);
76
2
}
77
78
6
BankWindow::~BankWindow()
79
{
80
4
}
81
82
void BankWindow::widgetShown(const Event &event)
83
{
84
    if (event.getSource() == this)
85
        bankHandler->check();
86
}
87
88
void BankWindow::bankMoneyChanged(const int money)
89
{
90
    // TRANSLATORS: bank window money label
91
    mBankMoneyLabel->setCaption(strprintf(_("Money in bank: %s"),
92
        UnitsDb::formatCurrency(money).c_str()));
93
}
94
95
void BankWindow::action(const ActionEvent &event)
96
{
97
    const std::string &eventId = event.getId();
98
    if (eventId == "deposit")
99
        bankHandler->deposit(mInputMoneyTextField->getValue());
100
    else if (eventId == "withdraw")
101
        bankHandler->withdraw(mInputMoneyTextField->getValue());
102

6
}