GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/chat/guildtab.cpp Lines: 1 35 2.9 %
Date: 2017-11-29 Branches: 2 60 3.3 %

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/guildtab.h"
24
25
#include "configuration.h"
26
#include "soundmanager.h"
27
28
#include "const/sound.h"
29
30
#include "gui/windows/chatwindow.h"
31
32
#include "input/inputmanager.h"
33
34
#include "net/guildhandler.h"
35
36
#include "utils/gettext.h"
37
38
#include "debug.h"
39
40
namespace EAthena
41
{
42
    extern Guild *taGuild;
43
}  // namespace EAthena
44
45
GuildTab::GuildTab(const Widget2 *const widget) :
46
    // TRANSLATORS: guild chat tab name
47
    ChatTab(widget, _("Guild"), "", "#Guild", ChatTabType::GUILD)
48
{
49
    setTabColors(ThemeColorId::GUILD_CHAT_TAB);
50
    mShowOnline = config.getBoolValue("showGuildOnline");
51
    config.addListener("showGuildOnline", this);
52
}
53
54
GuildTab::~GuildTab()
55
{
56
    config.removeListeners(this);
57
    CHECKLISTENERS
58
}
59
60
bool GuildTab::handleCommand(const std::string &restrict type,
61
                             const std::string &restrict args)
62
{
63
    if (type == "invite" && (EAthena::taGuild != nullptr))
64
    {
65
        guildHandler->invite(args);
66
    }
67
    else if (type == "leave" && (EAthena::taGuild != nullptr))
68
    {
69
        inputManager.executeChatCommand(InputAction::LEAVE_GUILD,
70
            std::string(),
71
            this);
72
    }
73
    else if (type == "kick" && (EAthena::taGuild != nullptr))
74
    {
75
        inputManager.executeChatCommand(InputAction::KICK_GUILD,
76
            args,
77
            this);
78
    }
79
    else if (type == "notice" && (EAthena::taGuild != nullptr))
80
    {
81
        inputManager.executeChatCommand(InputAction::GUILD_NOTICE,
82
            args,
83
            this);
84
    }
85
    else
86
    {
87
        return false;
88
    }
89
90
    return true;
91
}
92
93
void GuildTab::handleInput(const std::string &msg)
94
{
95
    if (EAthena::taGuild == nullptr)
96
        return;
97
98
    guildHandler->chat(ChatWindow::doReplace(msg));
99
}
100
101
void GuildTab::getAutoCompleteList(StringVect &names) const
102
{
103
    if (EAthena::taGuild != nullptr)
104
        EAthena::taGuild->getNames(names);
105
}
106
107
void GuildTab::getAutoCompleteCommands(StringVect &names) const
108
{
109
    names.push_back("/help");
110
    names.push_back("/invite ");
111
    names.push_back("/kick ");
112
    names.push_back("/notice ");
113
    names.push_back("/leave");
114
}
115
116
void GuildTab::playNewMessageSound() const
117
{
118
    soundManager.playGuiSound(SOUND_GUILD);
119
}
120
121
void GuildTab::optionChanged(const std::string &value)
122
{
123
    if (value == "showGuildOnline")
124
        mShowOnline = config.getBoolValue("showGuildOnline");
125

6
}