GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/netdebugtab.cpp Lines: 14 23 60.9 %
Date: 2019-10-12 Branches: 17 46 37.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2019  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/widgets/tabs/netdebugtab.h"
22
23
#include "being/localplayer.h"
24
25
#include "gui/widgets/containerplacer.h"
26
#include "gui/widgets/label.h"
27
#include "gui/widgets/layouthelper.h"
28
29
#include "net/packetcounters.h"
30
31
#include "utils/gettext.h"
32
#include "utils/stringutils.h"
33
34
#include "debug.h"
35
36
2
NetDebugTab::NetDebugTab(const Widget2 *const widget) :
37
    DebugTab(widget),
38

2
    mPingLabel(new Label(this, "                ")),
39

2
    mInPackets1Label(new Label(this, "                ")),
40


24
    mOutPackets1Label(new Label(this, "                "))
41
{
42
4
    LayoutHelper h(this);
43
2
    ContainerPlacer place = h.getPlacer(0, 0);
44
45
2
    place(0, 0, mPingLabel, 2, 1);
46
2
    place(0, 1, mInPackets1Label, 2, 1);
47
2
    place(0, 2, mOutPackets1Label, 2, 1);
48
49
2
    place.getCell().matchColWidth(0, 0);
50
2
    place = h.getPlacer(0, 1);
51
2
    setDimension(Rect(0, 0, 600, 300));
52
2
}
53
54
void NetDebugTab::logic()
55
{
56
    BLOCK_START("NetDebugTab::logic")
57
    if (localPlayer != nullptr)
58
    {
59
        // TRANSLATORS: debug window label
60
        mPingLabel->setCaption(strprintf(_("Ping: %s ms"),
61
            localPlayer->getPingTime().c_str()));
62
    }
63
    else
64
    {
65
        // TRANSLATORS: debug window label
66
        mPingLabel->setCaption(strprintf(_("Ping: %s ms"), "0"));
67
    }
68
    // TRANSLATORS: debug window label
69
    mInPackets1Label->setCaption(strprintf(_("In: %d bytes/s"),
70
        PacketCounters::getInBytes()));
71
    // TRANSLATORS: debug window label
72
    mOutPackets1Label->setCaption(strprintf(_("Out: %d bytes/s"),
73
        PacketCounters::getOutBytes()));
74
    BLOCK_END("NetDebugTab::logic")
75
2
}