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