GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/chat/partytab.cpp Lines: 1 45 2.2 %
Date: 2017-11-29 Branches: 2 64 3.1 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2008-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/widgets/tabs/chat/partytab.h"
24
25
#include "configuration.h"
26
#include "party.h"
27
#include "soundmanager.h"
28
29
#include "being/localplayer.h"
30
31
#include "const/sound.h"
32
33
#include "gui/windows/chatwindow.h"
34
35
#include "input/inputmanager.h"
36
37
#include "net/net.h"
38
#include "net/partyhandler.h"
39
40
#include "utils/gettext.h"
41
42
#include "debug.h"
43
44
PartyTab *partyTab = nullptr;
45
46
PartyTab::PartyTab(const Widget2 *const widget) :
47
    // TRANSLATORS: party chat tab name
48
    ChatTab(widget, _("Party"), "", "#Party", ChatTabType::PARTY)
49
{
50
    setTabColors(ThemeColorId::PARTY_CHAT_TAB);
51
    mShowOnline = config.getBoolValue("showPartyOnline");
52
    config.addListener("showPartyOnline", this);
53
}
54
55
PartyTab::~PartyTab()
56
{
57
    config.removeListeners(this);
58
    CHECKLISTENERS
59
}
60
61
void PartyTab::handleInput(const std::string &msg)
62
{
63
    partyHandler->chat(ChatWindow::doReplace(msg));
64
}
65
66
bool PartyTab::handleCommand(const std::string &restrict type,
67
                             const std::string &restrict args)
68
{
69
    if (type == "invite")
70
    {
71
        partyHandler->invite(args);
72
    }
73
    else if (type == "leave")
74
    {
75
        inputManager.executeChatCommand(InputAction::LEAVE_PARTY,
76
            args,
77
            this);
78
    }
79
    else if (type == "kick")
80
    {
81
        inputManager.executeChatCommand(InputAction::KICK_PARTY,
82
            args,
83
            this);
84
    }
85
    else if (type == "item")
86
    {
87
        inputManager.executeChatCommand(InputAction::PARTY_ITEM_SHARE,
88
            args,
89
            this);
90
    }
91
    else if (type == "autoitem")
92
    {
93
        inputManager.executeChatCommand(InputAction::PARTY_AUTO_ITEM_SHARE,
94
            args,
95
            this);
96
    }
97
    else if (type == "exp")
98
    {
99
        inputManager.executeChatCommand(InputAction::PARTY_EXP_SHARE,
100
            args,
101
            this);
102
    }
103
    else if (type == "setleader" &&
104
             Net::getNetworkType() != ServerType::TMWATHENA)
105
    {
106
        inputManager.executeChatCommand(
107
            InputAction::COMMAND_CHANGE_PARTY_LEADER,
108
            args,
109
            this);
110
    }
111
    else
112
    {
113
        return false;
114
    }
115
116
    return true;
117
}
118
119
void PartyTab::getAutoCompleteList(StringVect &names) const
120
{
121
    if (localPlayer == nullptr)
122
        return;
123
124
    const Party *const p = localPlayer->getParty();
125
126
    if (p != nullptr)
127
        p->getNames(names);
128
}
129
130
void PartyTab::getAutoCompleteCommands(StringVect &names) const
131
{
132
    names.push_back("/help");
133
    names.push_back("/invite ");
134
    names.push_back("/leave");
135
    names.push_back("/kick ");
136
    names.push_back("/item");
137
    names.push_back("/exp");
138
    if (Net::getNetworkType() != ServerType::TMWATHENA)
139
        names.push_back("/setleader ");
140
}
141
142
void PartyTab::playNewMessageSound() const
143
{
144
    soundManager.playGuiSound(SOUND_GUILD);
145
}
146
147
void PartyTab::optionChanged(const std::string &value)
148
{
149
    if (value == "showPartyOnline")
150
        mShowOnline = config.getBoolValue("showPartyOnline");
151

6
}