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

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2019  The ManaPlus Developers
4
 *  Copyright (C) 2019-2021  Andrei Karas
5
 *
6
 *  This file is part of The ManaPlus Client.
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  any later version.
12
 *
13
 *  This program is distributed in the hope that it will be useful,
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  GNU General Public License for more details.
17
 *
18
 *  You should have received a copy of the GNU General Public License
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
#include "gui/widgets/tabs/netdebugtab.h"
23
24
#include "being/localplayer.h"
25
26
#include "gui/widgets/containerplacer.h"
27
#include "gui/widgets/label.h"
28
#include "gui/widgets/layouthelper.h"
29
30
#include "net/packetcounters.h"
31
32
#include "utils/gettext.h"
33
#include "utils/stringutils.h"
34
35
#include "debug.h"
36
37
2
NetDebugTab::NetDebugTab(const Widget2 *const widget) :
38
    DebugTab(widget),
39

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

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


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