GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/insertcarddialog.cpp Lines: 14 22 63.6 %
Date: 2017-11-29 Branches: 7 22 31.8 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#include "gui/windows/insertcarddialog.h"
24
25
#include "gui/models/shopitems.h"
26
27
#include "gui/widgets/button.h"
28
#include "gui/widgets/shoplistbox.h"
29
30
#include "net/inventoryhandler.h"
31
32
#include "utils/gettext.h"
33
#include "utils/stringutils.h"
34
35
#include "resources/item/shopitem.h"
36
37
#include "debug.h"
38
39
2
InsertCardDialog::InsertCardDialog(const int itemIndex,
40
2
                                   const Item *const item) :
41
    SellDialog(IsSell_false, Advanced_false),
42
2
    mItemIndex(itemIndex)
43
{
44
    // TRANSLATORS: insert card dialog name
45
10
    setWindowName(_("Insert card"));
46
2
    if (item != nullptr)
47
    {
48
        // TRANSLATORS: insert card dialog name
49
8
        setCaption(strprintf(_("Insert card %s"),
50
4
            item->getName().c_str()));
51
    }
52
    else
53
    {
54
        // TRANSLATORS: insert card dialog name
55
        setCaption(strprintf(_("Insert card %s"),
56
            ""));
57
    }
58
2
}
59
60
2
void InsertCardDialog::initButtons()
61
{
62
    // TRANSLATORS: insert card dialog button
63
10
    mSellButton->setCaption(_("Insert"));
64
2
    mSellButton->adjustSize();
65
4
    mShopItems->setMergeDuplicates(false);
66
2
}
67
68
void InsertCardDialog::sellAction(const ActionEvent &event A_UNUSED)
69
{
70
    if (mAmountItems <= 0 || mAmountItems > mMaxItems)
71
        return;
72
73
    const int selectedItem = mShopItemList->getSelected();
74
    const ShopItem *const item = mShopItems->at(selectedItem);
75
    if (item == nullptr)
76
        return;
77
    inventoryHandler->insertCard(mItemIndex, item->getInvIndex());
78
    scheduleDelete();
79

6
}