GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/bankwindow.cpp Lines: 29 42 69.0 %
Date: 2018-07-14 Branches: 33 78 42.3 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2018  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
1
BankWindow::BankWindow() :
42
    // TRANSLATORS: bank window name
43
1
    Window(_("Bank"), Modal_false, nullptr, "bank.xml"),
44
    ActionListener(),
45
    BankListener(),
46
2
    mBankMoneyLabel(new Label(this, strprintf(
47
        // TRANSLATORS: bank window money label
48

2
        _("Money in bank: %s"), "            "))),
49
    mInputMoneyTextField(new IntTextField(this, 0, 0, 2147483647,
50

1
        Enable_true, 0)),
51
    // TRANSLATORS: bank window button
52
1
    mWithdrawButton(new Button(this, _("Withdraw"), "withdraw",
53

1
        BUTTON_SKIN, this)),
54
    // TRANSLATORS: bank window button
55
1
    mDepositButton(new Button(this, _("Deposit"), "deposit",
56




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

3
}