00001 /* 00002 * The Mana World 00003 * Copyright (C) 2008 The Mana World Development Team 00004 * 00005 * This file is part of The Mana World. 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 */ 00021 00022 #include "whispertab.h" 00023 00024 #include "localplayer.h" 00025 00026 #include "gui/palette.h" 00027 00028 #include "net/chathandler.h" 00029 #include "net/net.h" 00030 00031 #include "utils/gettext.h" 00032 #include "utils/strprintf.h" 00033 00034 WhisperTab::WhisperTab(const std::string &nick) : 00035 ChatTab(nick), 00036 mNick(nick) 00037 { 00038 setTabColor(guiPalette->getColor(Palette::WHISPER)); 00039 } 00040 00041 WhisperTab::~WhisperTab() 00042 { 00043 chatWindow->removeWhisper(mNick); 00044 } 00045 00046 void WhisperTab::handleInput(const std::string &msg) 00047 { 00048 if (msg.empty()) { 00049 chatLog(_("Cannot send empty chat!"), BY_SERVER, false); 00050 return; 00051 } 00052 00053 Net::getChatHandler()->privateMessage(mNick, msg); 00054 00055 chatLog(strprintf(_("%s: %s"), player_node->getName().c_str(), 00056 msg.c_str()), BY_PLAYER, false); 00057 } 00058 00059 void WhisperTab::handleCommand(const std::string &msg) 00060 { 00061 if (msg == "close") 00062 delete this; 00063 else 00064 ChatTab::handleCommand(msg); 00065 } 00066 00067 void WhisperTab::showHelp() 00068 { 00069 chatLog(_("/close > Close the whisper tab")); 00070 } 00071 00072 bool WhisperTab::handleCommand(const std::string &type, 00073 const std::string &args) 00074 { 00075 if (type == "help") 00076 { 00077 if (args == "close") 00078 { 00079 chatLog(_("Command: /close")); 00080 chatLog(_("This command closes the current whisper tab.")); 00081 } 00082 else 00083 return false; 00084 } 00085 else if (type == "close") 00086 { 00087 delete this; 00088 } 00089 else 00090 return false; 00091 00092 return true; 00093 }