GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/chat/whispertab.cpp Lines: 1 42 2.4 %
Date: 2017-11-29 Branches: 0 46 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 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/whispertab.h"
24
25
#include "being/localplayer.h"
26
27
#include "net/chathandler.h"
28
29
#include "gui/windows/chatwindow.h"
30
31
#include "gui/widgets/windowcontainer.h"
32
33
#include "utils/chatutils.h"
34
35
#include "debug.h"
36
37
WhisperTab::WhisperTab(const Widget2 *const widget,
38
                       const std::string &caption,
39
                       const std::string &nick) :
40
    ChatTab(widget, caption, nick, nick, ChatTabType::WHISPER),
41
    mNick(nick)
42
{
43
    setWhisperTabColors();
44
}
45
46
WhisperTab::~WhisperTab()
47
{
48
    if (chatWindow != nullptr)
49
        chatWindow->removeWhisper(mNick);
50
}
51
52
void WhisperTab::handleInput(const std::string &msg)
53
{
54
    std::string newMsg;
55
    newMsg = ChatWindow::doReplace(msg);
56
    chatHandler->privateMessage(mNick, newMsg);
57
58
    if (localPlayer != nullptr)
59
        chatLog(localPlayer->getName(), newMsg);
60
    else
61
        chatLog("?", newMsg);
62
}
63
64
void WhisperTab::handleCommandStr(const std::string &msg)
65
{
66
    if (msg == "close")
67
    {
68
        delete this;
69
        return;
70
    }
71
72
    const size_t pos = msg.find(' ');
73
    const std::string type(msg, 0, pos);
74
75
    if (type == "me")
76
    {
77
        const std::string args(msg, pos == std::string::npos
78
            ? msg.size() : pos + 1);
79
        std::string str = textToMe(args);
80
        chatHandler->privateMessage(mNick, str);
81
        if (localPlayer != nullptr)
82
            chatLog(localPlayer->getName(), str);
83
        else
84
            chatLog("?", str);
85
    }
86
    else
87
    {
88
        ChatTab::handleCommandStr(msg);
89
    }
90
}
91
92
bool WhisperTab::handleCommand(const std::string &restrict type,
93
                               const std::string &restrict args A_UNUSED)
94
{
95
    if (type == "close")
96
    {
97
        if (windowContainer != nullptr)
98
            windowContainer->scheduleDelete(this);
99
        else
100
            delete this;
101
        if (chatWindow != nullptr)
102
            chatWindow->defaultTab();
103
    }
104
    else
105
    {
106
        return false;
107
    }
108
109
    return true;
110
}
111
112
void WhisperTab::getAutoCompleteList(StringVect &names) const
113
{
114
    names.push_back(mNick);
115
}
116
117
void WhisperTab::getAutoCompleteCommands(StringVect& commands) const
118
{
119
    commands.push_back("/close");
120
}
121
122
void WhisperTab::setWhisperTabColors()
123
{
124
    setTabColors(ThemeColorId::WHISPER_TAB);
125
}
126
127
void WhisperTab::setWhisperTabOfflineColors()
128
{
129
    setTabColors(ThemeColorId::WHISPER_TAB_OFFLINE);
130
4
}