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