GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/chat/chattab.h Lines: 3 16 18.8 %
Date: 2017-11-29 Branches: 0 0 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
#ifndef GUI_WIDGETS_TABS_CHAT_CHATTAB_H
24
#define GUI_WIDGETS_TABS_CHAT_CHATTAB_H
25
26
#include "enums/gui/chatmsgtype.h"
27
#include "enums/gui/chattabtype.h"
28
29
#include "enums/simpletypes/ignorerecord.h"
30
#include "enums/simpletypes/online.h"
31
#include "enums/simpletypes/tryremovecolors.h"
32
33
#include "gui/widgets/browserbox.h"
34
35
#include "gui/widgets/tabs/tab.h"
36
37
#include "localconsts.h"
38
39
class ScrollArea;
40
41
#define debugMsg(str) \
42
    if (debugChatTab) \
43
        debugChatTab->chatLog(str, ChatMsgType::BY_SERVER);
44
45
#define setTabColors(name) \
46
    setTabColor(&getThemeColor(name), \
47
        &getThemeColor(name##_OUTLINE)); \
48
    setHighlightedTabColor(&getThemeColor(name##_HIGHLIGHTED), \
49
        &getThemeColor(name##_HIGHLIGHTED_OUTLINE)); \
50
    setSelectedTabColor(&getThemeColor(name##_SELECTED), \
51
        &getThemeColor(name##_SELECTED_OUTLINE))
52
53
/**
54
 * A tab for the chat window. This is special to ease chat handling.
55
 */
56
class ChatTab notfinal : public Tab
57
{
58
    public:
59
        /**
60
         * Constructor.
61
         */
62
        ChatTab(const Widget2 *const widget,
63
                const std::string &name,
64
                const std::string &channel,
65
                const std::string &logName,
66
                const ChatTabTypeT &type);
67
68
        A_DELETE_COPY(ChatTab)
69
70
        virtual ~ChatTab();
71
72
        /**
73
         * Adds a line of text to our message list. Parameters:
74
         *
75
         * @param line Text message.
76
         * @param own  Type of message (usually the owner-type).
77
         * @param ignoreRecord should this not be recorded?
78
         * @param tryRemoveColors try remove color if configured
79
         */
80
        void chatLog(std::string line,
81
                     ChatMsgTypeT own,
82
                     const IgnoreRecord ignoreRecord = IgnoreRecord_false,
83
                     const TryRemoveColors tryRemoveColors
84
                     = TryRemoveColors_true);
85
86
        /**
87
         * Adds the text to the message list
88
         *
89
         * @param msg  The message text which is to be sent.
90
         */
91
        void chatLog(const std::string &nick, std::string msg);
92
93
        /**
94
         * Determines whether the message is a command or message, then
95
         * sends the given message to the game server to be said, or to the
96
         * command handler
97
         *
98
         * @param msg  The message text which is to be sent.
99
         */
100
        void chatInput(const std::string &msg);
101
102
        /**
103
         * Scrolls the chat window
104
         *
105
         * @param amount direction and amount to scroll.  Negative numbers scroll
106
         * up, positive numbers scroll down.  The absolute amount indicates the
107
         * amount of 1/8ths of chat window real estate that should be scrolled.
108
         */
109
        void scroll(const int amount);
110
111
        /**
112
         * Clears the text from the tab
113
         */
114
        void clearText();
115
116
        /**
117
         * Handle special commands. Allows a tab to handle commands it
118
         * defines itself.
119
         *
120
         * @returns true  if the command was handled
121
         *          false if the command was not handled
122
         */
123
        virtual bool handleCommand(const std::string &restrict type A_UNUSED,
124
                                   const std::string &restrict args A_UNUSED)
125
        { return false; }
126
127
        /**
128
         * Handle special commands. Allows a tab to handle commands it
129
         * defines itself.
130
         *
131
         * @returns true  if the command was handled
132
         *          false if the command was not handled
133
         */
134
        virtual bool handleCommands(const std::string &type,
135
                                    const std::string &args);
136
137
        /**
138
         * Returns type of the being.
139
         */
140
        ChatTabTypeT getType() const noexcept2 A_WARN_UNUSED
141
        { return mType; }
142
143
        void saveToLogFile(const std::string &msg) const;
144
145
        const std::list<std::string> &getRows() const A_WARN_UNUSED
146
        { return mTextOutput->getRows(); }
147
148
        bool hasRows() const A_WARN_UNUSED
149
        { return mTextOutput->hasRows(); }
150
151
        void loadFromLogFile(const std::string &name);
152
153
        bool getAllowHighlight() const noexcept2 A_WARN_UNUSED
154
        { return mAllowHightlight; }
155
156
        void setAllowHighlight(const bool n) noexcept2
157
2
        { mAllowHightlight = n; }
158
159
        bool getRemoveNames() const noexcept2 A_WARN_UNUSED
160
        { return mRemoveNames; }
161
162
        void setRemoveNames(const bool n) noexcept2
163
        { mRemoveNames = n; }
164
165
        bool getNoAway() const noexcept2 A_WARN_UNUSED
166
        { return mNoAway; }
167
168
        void setNoAway(const bool n) noexcept2
169
        { mNoAway = n; }
170
171
        void addNewRow(std::string &line);
172
173
        void showOnline(const std::string &nick,
174
                        const Online online);
175
176
        virtual void playNewMessageSound() const;
177
178
        const std::string &getChannelName() const
179
        { return mChannelName; }
180
181
    protected:
182
        friend class ChatWindow;
183
        friend class WhisperWindow;
184
185
2
        void setCurrent() override final
186
4
        { setFlash(0); }
187
188
        virtual void handleInput(const std::string &msg);
189
190
        virtual void handleCommandStr(const std::string &msg);
191
192
        virtual void handleHelp(const std::string &msg);
193
194
        virtual void getAutoCompleteList(StringVect &names A_UNUSED) const
195
        {}
196
197
        virtual void getAutoCompleteCommands(StringVect &names A_UNUSED) const
198
        {}
199
200
        void addRow(std::string &line);
201
202
        BrowserBox *mTextOutput A_NONNULLPOINTER;
203
        ScrollArea *mScrollArea;
204
        std::string mChannelName;
205
        std::string mLogName;
206
        ChatTabTypeT mType;
207
        bool mAllowHightlight;
208
        bool mRemoveNames;
209
        bool mNoAway;
210
        bool mShowOnline;
211
};
212
213
extern ChatTab *localChatTab;
214
extern ChatTab *debugChatTab;
215
216
#endif  // GUI_WIDGETS_TABS_CHAT_CHATTAB_H