summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rwxr-xr-xconfigure.ac1
-rw-r--r--src/gui/chat.cpp49
-rw-r--r--src/gui/chat.h30
4 files changed, 51 insertions, 31 deletions
diff --git a/ChangeLog b/ChangeLog
index 26288963..b0ca058f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,8 @@
get the data from when using --skipupdate.
* configure.ac, data/Makefile.am, data/fonts/Makefile.am: Fixed
installing of dejavusans.ttf font.
+ * src/gui/chat.h, src/gui/chat.cpp: Merged two maps into one, avoid
+ non-const operator[] and check whether channel was found.
2008-04-19 Yohann Ferreira <bertram@cegetel.net>
diff --git a/configure.ac b/configure.ac
index 506ef0f7..5cfdcc65 100755
--- a/configure.ac
+++ b/configure.ac
@@ -110,6 +110,7 @@ AC_CONFIG_FILES([
Makefile
src/Makefile
data/Makefile
+data/fonts/Makefile
data/graphics/Makefile
data/graphics/gui/Makefile
data/graphics/images/Makefile
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index a9f3b931..2ed6cade 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -76,8 +76,8 @@ ChatWindow::ChatWindow():
mChatTabs->addTab("General", scrollArea);
mChatTabs->setPosition(mChatTabs->getFrameSize(), mChatTabs->getFrameSize());
- mChannelOutput["General"] = textOutput;
- mChannelScroll["General"] = scrollArea;
+ mChannels.insert(
+ std::make_pair("General", ChatArea(textOutput, scrollArea)));
add(mChatTabs);
add(mChatInput);
@@ -99,9 +99,6 @@ ChatWindow::logic()
// todo: only do this when the size changes (updateWidgets?)
const gcn::Rectangle area = getChildrenArea();
- std::string channelName = mChatTabs->getSelectedTab()->getCaption();
- ScrollArea *scroll = mChannelScroll[channelName];
-
mChatInput->setPosition(mChatInput->getFrameSize(),
area.height - mChatInput->getHeight() -
mChatInput->getFrameSize());
@@ -110,9 +107,14 @@ ChatWindow::logic()
mChatTabs->setWidth(area.width - 2 * mChatTabs->getFrameSize());
mChatTabs->setHeight(area.height - 2 * mChatTabs->getFrameSize());
- scroll->setWidth(area.width - 2 * scroll->getFrameSize());
- scroll->setHeight(area.height - 2 * scroll->getFrameSize() -
- mChatInput->getHeight() - 26);
+ const std::string &channelName = mChatTabs->getSelectedTab()->getCaption();
+ ChannelMap::const_iterator chan = mChannels.find(channelName);
+ if (chan != mChannels.end()) {
+ ScrollArea *scroll = chan->second.scroll;
+ scroll->setWidth(area.width - 2 * scroll->getFrameSize());
+ scroll->setHeight(area.height - 2 * scroll->getFrameSize() -
+ mChatInput->getHeight() - 26);
+ }
Window::logic();
}
@@ -120,6 +122,13 @@ ChatWindow::logic()
void
ChatWindow::chatLog(std::string line, int own, const std::string &channelName)
{
+ ChannelMap::const_iterator chan = mChannels.find(channelName);
+ if (chan == mChannels.end())
+ return;
+
+ BrowserBox * const output = chan->second.browser;
+ ScrollArea * const scroll = chan->second.scroll;
+
// Trim whitespace
trim(line);
@@ -128,15 +137,6 @@ ChatWindow::chatLog(std::string line, int own, const std::string &channelName)
tmp.nick = "";
tmp.text = line;
- BrowserBox *output = mChannelOutput[channelName];
- ScrollArea *scroll = mChannelScroll[channelName];
-
- // Fix the owner of welcome message.
- if (line.substr(0, 7) == "Welcome")
- {
- own = BY_SERVER;
- }
-
std::string::size_type pos = line.find(" : ");
if (pos != std::string::npos) {
tmp.nick = line.substr(0, pos);
@@ -372,9 +372,9 @@ void ChatWindow::chatSend(std::string const &nick, std::string const &msg,
}
else if (command == "clear")
{
- BrowserBox *output = mChannelOutput[channelName];
- if (output)
- output->clearRows();
+ ChannelMap::const_iterator chan = mChannels.find(channelName);
+ if (chan != mChannels.end())
+ chan->second.browser->clearRows();
}
else
{
@@ -485,14 +485,13 @@ ChatWindow::removeChannel(const std::string &channelName)
void
ChatWindow::removeChannel(Channel *channel)
{
- if(channel)
+ if (channel)
{
gcn::Tab *tab = mChatTabs->getTab(channel->getName());
if (!tab)
return;
mChatTabs->removeTab(tab);
- mChannelOutput.erase(channel->getName());
- mChannelScroll.erase(channel->getName());
+ mChannels.erase(channel->getName());
channelManager->removeChannel(channel);
logic();
@@ -513,8 +512,8 @@ ChatWindow::createNewChannelTab(const std::string &channelName)
// Add channel to the tabbed area
mChatTabs->addTab(channelName, scrollArea);
- mChannelOutput[channelName] = textOutput;
- mChannelScroll[channelName] = scrollArea;
+ mChannels.insert(
+ std::make_pair(channelName, ChatArea(textOutput, scrollArea)));
// Ask for channel users
Net::ChatServer::getUserList(channelName);
diff --git a/src/gui/chat.h b/src/gui/chat.h
index ab8c3985..08fed0be 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -234,20 +234,38 @@ class ChatWindow : public Window, public gcn::ActionListener,
int own;
};
+ /**
+ * A structure combining a BrowserBox with its ScrollArea.
+ */
+ struct ChatArea
+ {
+ ChatArea(BrowserBox *b, ScrollArea *s):
+ browser(b), scroll(s)
+ {}
+
+ BrowserBox *browser;
+ ScrollArea *scroll;
+ };
+
#if 0
/** Constructs failed messages for actions */
std::string const_msg(CHATSKILL);*/
#endif
- TabbedArea *mChatTabs; /** < Chat Tabbed area for holding each channel */
- gcn::TextField *mChatInput; /**< Input box for typing chat messages */
- std::map<std::string, BrowserBox*> mChannelOutput; /**< Map each TextOutput to a tab */
- std::map<std::string, ScrollArea*> mChannelScroll; /**< Map each ScrollArea to a tab */
+ /** Tabbed area for holding each channel. */
+ TabbedArea *mChatTabs;
+
+ /** Input box for typing chat messages. */
+ gcn::TextField *mChatInput;
+
+ typedef std::map<const std::string, ChatArea> ChannelMap;
+ /** Map each tab to its browser and scroll area. */
+ ChannelMap mChannels;
typedef std::list<std::string> History;
typedef History::iterator HistoryIterator;
- History mHistory; /**< Command history */
- HistoryIterator mCurHist; /**< History iterator */
+ History mHistory; /**< Command history. */
+ HistoryIterator mCurHist; /**< History iterator. */
};
extern ChatWindow *chatWindow;