GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/eggselectiondialog.cpp Lines: 12 19 63.2 %
Date: 2017-11-29 Branches: 5 16 31.3 %

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/eggselectiondialog.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
34
#include "resources/item/shopitem.h"
35
36
#include "debug.h"
37
38
2
EggSelectionDialog::EggSelectionDialog() :
39
2
    SellDialog(IsSell_false, Advanced_false)
40
{
41
    // TRANSLATORS: egg selection dialog name
42
10
    setWindowName(_("Select egg"));
43
    // TRANSLATORS: egg selection dialog name
44
10
    setCaption(_("Select egg"));
45
2
}
46
47
2
void EggSelectionDialog::initButtons()
48
{
49
2
    logger->log("EggSelectionDialog::initButtons");
50
    // TRANSLATORS: egg selection dialog button
51
10
    mSellButton->setCaption(_("Select"));
52
2
    mSellButton->adjustSize();
53
4
    mShopItems->setMergeDuplicates(false);
54
2
}
55
56
void EggSelectionDialog::sellAction(const ActionEvent &event A_UNUSED)
57
{
58
    if (mAmountItems <= 0 || mAmountItems > mMaxItems)
59
        return;
60
61
    const int selectedItem = mShopItemList->getSelected();
62
    const ShopItem *const item = mShopItems->at(selectedItem);
63
    if (item == nullptr)
64
        return;
65
    inventoryHandler->selectEgg(item);
66
    scheduleDelete();
67

6
}