summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2010-01-08 16:03:29 +0200
committerBlue <bluesansdouze@gmail.com>2010-01-08 23:05:32 +0100
commitc1ddf4c0840bb15016dc69af4a4751d09908393f (patch)
tree26b8f6a28a469a64208eb9f475fb5e26de13b29b /src/gui
parent9b6e5a3189311d5704993d41a1fa195e006a57af (diff)
downloadmana-client-c1ddf4c0840bb15016dc69af4a4751d09908393f.tar.gz
mana-client-c1ddf4c0840bb15016dc69af4a4751d09908393f.tar.bz2
mana-client-c1ddf4c0840bb15016dc69af4a4751d09908393f.tar.xz
mana-client-c1ddf4c0840bb15016dc69af4a4751d09908393f.zip
Small refactoring in chat auto completing
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/chat.cpp58
-rw-r--r--src/gui/chat.h4
-rw-r--r--src/gui/partywindow.cpp23
-rw-r--r--src/gui/partywindow.h3
4 files changed, 51 insertions, 37 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index af0c3808..c9defe33 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -531,13 +531,16 @@ void ChatWindow::autoComplete()
ChatTab *cTab = static_cast<ChatTab*>(mChatTabs->getSelectedTab());
+ std::vector<std::string> nameList;
if (cTab && cTab->getType() == ChatTab::PARTY)
{
- newName = partyWindow->getAutoCompleteName(name);
+ partyWindow->getNames(nameList);
+ newName = autoComplete(nameList, name);
}
if (newName == "")
{
- newName = beingManager->getAutoCompletePlayerName(name);
+ beingManager->getPlayerNames(nameList, true);
+ newName = autoComplete(nameList, name);
}
if (newName == "")
{
@@ -556,10 +559,44 @@ void ChatWindow::autoComplete()
}
}
+std::string ChatWindow::autoComplete(std::vector<std::string> &names,
+ std::string partName) const
+{
+ std::vector<std::string>::iterator i = names.begin();
+ toLower(partName);
+ std::string newName("");
+
+ while (i != names.end())
+ {
+ if (!i->empty())
+ {
+ std::string name = *i;
+ toLower(name);
+
+ std::string::size_type pos = name.find(partName, 0);
+ if (pos == 0)
+ {
+ if (newName != "")
+ {
+ toLower(newName);
+ newName = findSameSubstring(name, newName);
+ }
+ else
+ {
+ newName = *i;
+ }
+ }
+ }
+ ++i;
+ }
+
+ return newName;
+}
+
std::string ChatWindow::autoCompleteHistory(std::string partName)
{
History::iterator i = mHistory.begin();
- std::string newName = "";
+ std::vector<std::string> nameList;
while (i != mHistory.end())
{
@@ -572,20 +609,9 @@ std::string ChatWindow::autoCompleteHistory(std::string partName)
line = line.substr(0, f);
if (line != "")
{
- std::string::size_type pos = line.find(partName, 0);
- if (pos == 0)
- {
- if (newName != "")
- {
- newName = findSameSubstring(line, newName);
- }
- else
- {
- newName = line;
- }
- }
+ nameList.push_back(line);
}
++i;
}
- return newName;
+ return autoComplete(nameList, partName);
}
diff --git a/src/gui/chat.h b/src/gui/chat.h
index b64ea5e8..4516257f 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -32,6 +32,7 @@
#include <list>
#include <string>
#include <map>
+#include <vector>
class BrowserBox;
class Channel;
@@ -191,6 +192,9 @@ class ChatWindow : public Window,
std::string autoCompleteHistory(std::string partName);
+ std::string autoComplete(std::vector<std::string> &names,
+ std::string partName) const;
+
/** Used for showing item popup on clicking links **/
ItemLinkHandler *mItemLinkHandler;
Recorder *mRecorder;
diff --git a/src/gui/partywindow.cpp b/src/gui/partywindow.cpp
index ae8112c8..67f1d4c0 100644
--- a/src/gui/partywindow.cpp
+++ b/src/gui/partywindow.cpp
@@ -254,11 +254,10 @@ void PartyWindow::buildLayout()
}
}
-std::string PartyWindow::getAutoCompleteName(std::string partName)
+void PartyWindow::getNames(std::vector<std::string> &names)
{
PartyList::iterator i = mMembers.begin();
- std::transform(partName.begin(), partName.end(), partName.begin(), tolower);
- std::string newName("");
+ names.clear();
while (i != mMembers.end())
{
@@ -266,24 +265,8 @@ std::string PartyWindow::getAutoCompleteName(std::string partName)
if (member->getAvatar() && member->getAvatar()->getName() != "")
{
std::string name = member->getAvatar()->getName();
- std::transform(name.begin(), name.end(), name.begin(), tolower);
-
- std::string::size_type pos = name.find(partName, 0);
- if (pos == 0)
- {
- if (newName != "")
- {
- std::transform(newName.begin(), newName.end(), newName.begin(), tolower);
- newName = findSameSubstring(name, newName);
- }
- else
- {
- newName = member->getAvatar()->getName();
- }
- }
+ names.push_back(name);
}
++i;
}
-
- return newName;
}
diff --git a/src/gui/partywindow.h b/src/gui/partywindow.h
index ed217910..0fe2986f 100644
--- a/src/gui/partywindow.h
+++ b/src/gui/partywindow.h
@@ -32,6 +32,7 @@
#include <string>
#include <map>
+#include <vector>
class PartyWindow;
@@ -127,7 +128,7 @@ class PartyWindow : public Window, gcn::ActionListener
void clearMembers();
- std::string getAutoCompleteName(std::string partName);
+ void getNames(std::vector<std::string> &names);
private:
/**