ManaPlus
whispertab.cpp
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-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 
24 
25 #include "being/localplayer.h"
26 
27 #include "net/chathandler.h"
28 
29 #include "gui/windows/chatwindow.h"
30 
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 {
44 }
45 
47 {
48  if (chatWindow != nullptr)
50 }
51 
52 void WhisperTab::handleInput(const std::string &msg)
53 {
54  std::string newMsg;
55  newMsg = ChatWindow::doReplace(msg);
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);
81  if (localPlayer != nullptr)
83  else
84  chatLog("?", str);
85  }
86  else
87  {
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)
99  else
100  delete this;
101  if (chatWindow != nullptr)
103  }
104  else
105  {
106  return false;
107  }
108 
109  return true;
110 }
111 
113 {
114  names.push_back(mNick);
115 }
116 
118 {
119  commands.push_back("/close");
120 }
121 
123 {
125 }
126 
128 {
130 }
std::string mNick
Definition: whispertab.h:70
ChatWindow * chatWindow
Definition: chatwindow.cpp:88
void scheduleDelete(Widget *const widget)
bool handleCommand(const std::string &type, const std::string &args)
Definition: whispertab.cpp:92
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord=IgnoreRecord_false, const TryRemoveColors tryRemoveColors=TryRemoveColors_true)
Definition: chattab.cpp:109
WindowContainer * windowContainer
void removeWhisper(const std::string &nick)
Definition: chatwindow.cpp:591
bool msg(InputEvent &event)
Definition: chat.cpp:38
std::vector< std::string > StringVect
Definition: stringvector.h:28
void handleCommandStr(const std::string &msg)
Definition: whispertab.cpp:64
void getAutoCompleteList(StringVect &names) const
Definition: whispertab.cpp:112
virtual void privateMessage(const std::string &recipient, const std::string &text) const =0
#define setTabColors(name)
Definition: chattab.h:45
void setWhisperTabColors()
Definition: whispertab.cpp:122
LocalPlayer * localPlayer
WhisperTab(const Widget2 *const widget, const std::string &caption, const std::string &nick)
Definition: whispertab.cpp:37
static std::string doReplace(const std::string &msg)
const std::string & getName() const
Definition: being.h:233
void getAutoCompleteCommands(StringVect &commands) const
Definition: whispertab.cpp:117
void defaultTab()
Definition: chatwindow.cpp:426
std::string textToMe(const std::string &str)
Definition: chatutils.cpp:198
#define A_UNUSED
Definition: localconsts.h:171
Net::ChatHandler * chatHandler
Definition: net.cpp:80
#define restrict
Definition: localconsts.h:176
void handleInput(const std::string &msg)
Definition: whispertab.cpp:52
void setWhisperTabOfflineColors()
Definition: whispertab.cpp:127
virtual void handleCommandStr(const std::string &msg)
Definition: chattab.cpp:440