ManaPlus
chattab.h
Go to the documentation of this file.
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 
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 
62 class ChatTab notfinal : public Tab
63 {
64  public:
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 
75 
76  ~ChatTab() override;
77 
86  void chatLog(std::string line,
87  ChatMsgTypeT own,
88  const IgnoreRecord ignoreRecord,
89  const TryRemoveColors tryRemoveColors);
90 
96  void chatLog(const std::string &nick, std::string msg);
97 
105  void chatInput(const std::string &msg);
106 
114  void scroll(const int amount);
115 
119  void clearText();
120 
128  virtual bool handleCommand(const std::string &restrict type A_UNUSED,
129  const std::string &restrict args A_UNUSED)
130  { return false; }
131 
139  virtual bool handleCommands(const std::string &type,
140  const std::string &args);
141 
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 
159  { return mAllowHightlight; }
160 
161  void setAllowHighlight(const bool n) noexcept2
162  { mAllowHightlight = n; }
163 
165  { return mRemoveNames; }
166 
167  void setRemoveNames(const bool n) noexcept2
168  { mRemoveNames = n; }
169 
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 
191  { 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 
209  std::string mChannelName;
210  std::string mLogName;
214  bool mNoAway;
216 };
217 
218 extern ChatTab *localChatTab;
219 extern ChatTab *debugChatTab;
220 
221 #endif // GUI_WIDGETS_TABS_CHAT_CHATTAB_H
ChatMsgType ::T ChatMsgTypeT
Definition: chatmsgtype.h:41
ChatTab * debugChatTab
Definition: chattab.cpp:63
ChatTab * localChatTab
Definition: chattab.cpp:62
ChatTabType ::T ChatTabTypeT
Definition: chattabtype.h:49
bool hasRows() const
Definition: browserbox.h:127
TextRows & getRows()
Definition: browserbox.h:124
void setRemoveNames(const bool n)
Definition: chattab.h:167
bool mShowOnline
Definition: chattab.h:215
virtual void getAutoCompleteList(StringVect &names) const
Definition: chattab.h:199
bool getRemoveNames() const
Definition: chattab.h:164
ChatTab(const Widget2 *const widget, const std::string &name, const std::string &channel, const std::string &logName, const ChatTabTypeT &type)
Definition: chattab.cpp:67
void saveToLogFile(const std::string &msg) const
Definition: chattab.cpp:468
virtual void handleInput(const std::string &msg)
Definition: chattab.cpp:433
virtual bool handleCommand(const std::string &type, const std::string &args)
Definition: chattab.h:128
ChatTabTypeT getType() const
Definition: chattab.h:145
void setAllowHighlight(const bool n)
Definition: chattab.h:161
std::string mLogName
Definition: chattab.h:210
virtual void getAutoCompleteCommands(StringVect &names) const
Definition: chattab.h:202
virtual void handleHelp(const std::string &msg)
Definition: chattab.cpp:452
bool mRemoveNames
Definition: chattab.h:213
void setCurrent()
Definition: chattab.h:190
void addRow(std::string &line)
Definition: chattab.cpp:488
bool getAllowHighlight() const
Definition: chattab.h:158
void addNewRow(std::string &line)
Definition: chattab.cpp:526
ChatTabTypeT mType
Definition: chattab.h:211
void setNoAway(const bool n)
Definition: chattab.h:173
friend class WhisperWindow
Definition: chattab.h:188
const std::list< std::string > & getRows() const
Definition: chattab.h:150
ScrollArea * mScrollArea
Definition: chattab.h:208
bool mAllowHightlight
Definition: chattab.h:212
bool hasRows() const
Definition: chattab.h:153
~ChatTab()
Definition: chattab.cpp:102
virtual bool handleCommands(const std::string &type, const std::string &args)
Definition: chattab.cpp:461
void scroll(const int amount)
Definition: chattab.cpp:419
bool getNoAway() const
Definition: chattab.h:170
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
Definition: chattab.cpp:111
void chatInput(const std::string &msg)
Definition: chattab.cpp:382
void showOnline(const std::string &nick, const Online online)
Definition: chattab.cpp:547
virtual void handleCommandStr(const std::string &msg)
Definition: chattab.cpp:441
bool mNoAway
Definition: chattab.h:214
void clearText()
Definition: chattab.cpp:428
std::string mChannelName
Definition: chattab.h:209
void loadFromLogFile(const std::string &name)
Definition: chattab.cpp:510
virtual void playNewMessageSound() const
Definition: chattab.cpp:542
BrowserBox * mTextOutput
Definition: chattab.h:207
const std::string & getChannelName() const
Definition: chattab.h:183
Definition: tab.h:88
void setFlash(const int flash)
Definition: tab.h:175
bool IgnoreRecord
Definition: ignorerecord.h:30
#define restrict
Definition: localconsts.h:165
#define override
Definition: localconsts.h:47
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define notfinal
Definition: localconsts.h:261
#define A_NONNULLPOINTER
Definition: localconsts.h:266
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
#define A_UNUSED
Definition: localconsts.h:160
bool msg(InputEvent &event)
Definition: chat.cpp:39
bool Online
Definition: online.h:30
std::vector< std::string > StringVect
Definition: stringvector.h:29
bool TryRemoveColors