|
|
|
@ -31,6 +31,7 @@
|
|
|
|
|
#include "chat_text_manager.h"
|
|
|
|
|
#include "people_interraction.h"
|
|
|
|
|
#include "../user_entity.h"
|
|
|
|
|
#include "nel/misc/o_xml.h"
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
using namespace NLMISC;
|
|
|
|
@ -191,21 +192,28 @@ sint CPeopleList::getIndexFromContainerID(const std::string &id) const
|
|
|
|
|
//==================================================================
|
|
|
|
|
bool CPeopleList::sortExByContactId(const CPeople& a, const CPeople& b)
|
|
|
|
|
{
|
|
|
|
|
if (a.Group == b.Group)
|
|
|
|
|
return (a.ContactId < b.ContactId);
|
|
|
|
|
else
|
|
|
|
|
return (a.Group < b.Group);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//==================================================================
|
|
|
|
|
bool CPeopleList::sortExByName(const CPeople& a, const CPeople& b)
|
|
|
|
|
{
|
|
|
|
|
if (a.Group == b.Group) {
|
|
|
|
|
ucstring name_a = toUpper(a.getName());
|
|
|
|
|
ucstring name_b = toUpper(b.getName());
|
|
|
|
|
|
|
|
|
|
return (name_a < name_b);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return (a.Group < b.Group);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//==================================================================
|
|
|
|
|
bool CPeopleList::sortExByOnline(const CPeople& a, const CPeople& b)
|
|
|
|
|
{
|
|
|
|
|
if (a.Group == b.Group) {
|
|
|
|
|
ucstring name_a = toUpper(a.getName());
|
|
|
|
|
ucstring name_b = toUpper(b.getName());
|
|
|
|
|
|
|
|
|
@ -234,9 +242,9 @@ bool CPeopleList::sortExByOnline(const CPeople& a, const CPeople& b)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Should not get here so just return something
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return (a.Group < b.Group);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//==================================================================
|
|
|
|
@ -245,9 +253,16 @@ void CPeopleList::sortEx(TSortOrder order)
|
|
|
|
|
// remove all people from the father container
|
|
|
|
|
if (!_BaseContainer) return;
|
|
|
|
|
uint k;
|
|
|
|
|
|
|
|
|
|
for(k = 0; k < _Peoples.size(); ++k)
|
|
|
|
|
{
|
|
|
|
|
_BaseContainer->detachContainer(_Peoples[k].Container);
|
|
|
|
|
CGroupContainer *parentContainer = _Peoples[k].Container->getProprietaryContainer();
|
|
|
|
|
parentContainer->detachContainer(_Peoples[k].Container);
|
|
|
|
|
}
|
|
|
|
|
for (k = 0; k < _GroupContainers.size(); ++k)
|
|
|
|
|
{
|
|
|
|
|
if (_GroupContainers[k].second->getProprietaryContainer() != NULL)
|
|
|
|
|
_BaseContainer->detachContainer(_GroupContainers[k].second);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (order)
|
|
|
|
@ -265,9 +280,29 @@ void CPeopleList::sortEx(TSortOrder order)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CGroupContainer *group = _BaseContainer;
|
|
|
|
|
ucstring groupName = "";
|
|
|
|
|
uint groupIndex = 0;
|
|
|
|
|
|
|
|
|
|
for(k = 0; k < _Peoples.size(); ++k)
|
|
|
|
|
{
|
|
|
|
|
_BaseContainer->attachContainer(_Peoples[k].Container);
|
|
|
|
|
bool newGroup = false;
|
|
|
|
|
if (k == 0)
|
|
|
|
|
{
|
|
|
|
|
newGroup = true;
|
|
|
|
|
}
|
|
|
|
|
while (groupIndex < _GroupContainers.size() && _GroupContainers[groupIndex].first != _Peoples[k].Group.toString())
|
|
|
|
|
{
|
|
|
|
|
newGroup = true;
|
|
|
|
|
++groupIndex;
|
|
|
|
|
}
|
|
|
|
|
if (newGroup && groupIndex < _GroupContainers.size())
|
|
|
|
|
{
|
|
|
|
|
group = _GroupContainers[groupIndex].second;
|
|
|
|
|
groupName = _GroupContainers[groupIndex].first;
|
|
|
|
|
_BaseContainer->attachContainer(group);
|
|
|
|
|
}
|
|
|
|
|
group->attachContainer(_Peoples[k].Container);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -415,8 +450,9 @@ void CPeopleList::removePeople(uint index)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (_BaseContainer)
|
|
|
|
|
_BaseContainer->detachContainer(_Peoples[index].Container);
|
|
|
|
|
CGroupContainer *parentContainer = _Peoples[index].Container->getProprietaryContainer();
|
|
|
|
|
if (parentContainer)
|
|
|
|
|
parentContainer->detachContainer(_Peoples[index].Container);
|
|
|
|
|
}
|
|
|
|
|
CInterfaceManager *im = CInterfaceManager::getInstance();
|
|
|
|
|
CInterfaceGroup *pRoot = dynamic_cast<CInterfaceGroup*>(CWidgetManager::getInstance()->getElementFromId("ui:interface"));
|
|
|
|
@ -447,6 +483,150 @@ void CPeopleList::setContactId(uint index, uint32 contactId)
|
|
|
|
|
_Peoples[index].ContactId = contactId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//==================================================================
|
|
|
|
|
void CPeopleList::changeGroup(uint index, const ucstring &groupName)
|
|
|
|
|
{
|
|
|
|
|
if (index >= _Peoples.size())
|
|
|
|
|
{
|
|
|
|
|
nlwarning("<CPeopleList::changeGroup> bad index.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ucstring group = groupName;
|
|
|
|
|
if (group.toString() == "General")
|
|
|
|
|
group = ucstring("");
|
|
|
|
|
_Peoples[index].Group = group;
|
|
|
|
|
|
|
|
|
|
for (uint k = 0; k < _GroupContainers.size(); ++k)
|
|
|
|
|
{
|
|
|
|
|
if (_GroupContainers[k].first == group.toString())
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vector<pair<string, string> > properties;
|
|
|
|
|
properties.push_back(make_pair(string("posparent"), string("parent")));
|
|
|
|
|
properties.push_back(make_pair(string("id"), _ContainerID + "_group_" + toString(_GroupContainers.size())));
|
|
|
|
|
if (group.toString() == "")
|
|
|
|
|
properties.push_back(make_pair(string("title"), "General"));
|
|
|
|
|
else
|
|
|
|
|
properties.push_back(make_pair(string("title"), group.toString()));
|
|
|
|
|
CGroupContainer *gc = dynamic_cast<CGroupContainer *>(CWidgetManager::getInstance()->getParser()->createGroupInstance("people_list_group_header", "ui:interface", properties, false));
|
|
|
|
|
|
|
|
|
|
if (group.toString() == "")
|
|
|
|
|
gc->setUCTitle(ucstring("General"));
|
|
|
|
|
else
|
|
|
|
|
gc->setUCTitle(group.toString());
|
|
|
|
|
gc->setSavable(false);
|
|
|
|
|
|
|
|
|
|
CInterfaceGroup *pRoot = dynamic_cast<CInterfaceGroup*>(CWidgetManager::getInstance()->getElementFromId("ui:interface"));
|
|
|
|
|
pRoot->addGroup (gc);
|
|
|
|
|
_BaseContainer->attachContainer(gc);
|
|
|
|
|
|
|
|
|
|
_GroupContainers.push_back(make_pair(group.toString(), gc));
|
|
|
|
|
|
|
|
|
|
std::sort(_GroupContainers.begin(), _GroupContainers.end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//==================================================================
|
|
|
|
|
void CPeopleList::readContactGroups()
|
|
|
|
|
{
|
|
|
|
|
_GroupContainers.clear();
|
|
|
|
|
const std::string filename = CInterfaceManager::getInstance()->getSaveFileName("contactgroups", "xml");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
CIFile fd;
|
|
|
|
|
if (fd.open(CPath::lookup(filename)))
|
|
|
|
|
{
|
|
|
|
|
CIXml stream;
|
|
|
|
|
stream.init(fd);
|
|
|
|
|
|
|
|
|
|
xmlKeepBlanksDefault(0);
|
|
|
|
|
xmlNodePtr root = stream.getRootNode();
|
|
|
|
|
|
|
|
|
|
if (!root) return;
|
|
|
|
|
|
|
|
|
|
xmlNodePtr node = root->children;
|
|
|
|
|
uint nb = 0;
|
|
|
|
|
while (node)
|
|
|
|
|
{
|
|
|
|
|
CXMLAutoPtr propName = xmlGetProp(node, (xmlChar*)"name");
|
|
|
|
|
CXMLAutoPtr propGroup = xmlGetProp(node, (xmlChar*)"group");
|
|
|
|
|
if (propName && propGroup)
|
|
|
|
|
{
|
|
|
|
|
sint index = getIndexFromName(propName.str());
|
|
|
|
|
if (index < _Peoples.size())
|
|
|
|
|
{
|
|
|
|
|
_Peoples[index].Group = propGroup.str();
|
|
|
|
|
if (_GroupContainers.empty() || _GroupContainers.back().first != propName.str()) {
|
|
|
|
|
vector<pair<string, string> > properties;
|
|
|
|
|
properties.push_back(make_pair(string("posparent"), string("parent")));
|
|
|
|
|
properties.push_back(make_pair(string("id"), _ContainerID + "_group_" + toString(_GroupContainers.size())));
|
|
|
|
|
if (propGroup.str() == "")
|
|
|
|
|
properties.push_back(make_pair(string("title"), "General"));
|
|
|
|
|
else
|
|
|
|
|
properties.push_back(make_pair(string("title"), propGroup.str()));
|
|
|
|
|
CInterfaceGroup *group = CWidgetManager::getInstance()->getParser()->createGroupInstance("people_list_group_header", "ui:interface", properties, false);
|
|
|
|
|
CGroupContainer *gc = dynamic_cast<CGroupContainer *>(group);
|
|
|
|
|
if (propGroup.str() == "")
|
|
|
|
|
gc->setUCTitle(ucstring("General"));
|
|
|
|
|
else
|
|
|
|
|
gc->setUCTitle(propGroup.str());
|
|
|
|
|
gc->setSavable(false);
|
|
|
|
|
|
|
|
|
|
CInterfaceGroup *pRoot = dynamic_cast<CInterfaceGroup*>(CWidgetManager::getInstance()->getElementFromId("ui:interface"));
|
|
|
|
|
pRoot->addGroup (gc);
|
|
|
|
|
_BaseContainer->attachContainer(gc);
|
|
|
|
|
|
|
|
|
|
_GroupContainers.push_back(make_pair(propGroup.str(), gc));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
node = node->next;
|
|
|
|
|
nb++;
|
|
|
|
|
}
|
|
|
|
|
fd.close();
|
|
|
|
|
}
|
|
|
|
|
std::sort(_GroupContainers.begin(), _GroupContainers.end());
|
|
|
|
|
}
|
|
|
|
|
catch (const Exception &e)
|
|
|
|
|
{
|
|
|
|
|
nlwarning("Error while parsing xml file %s : %s", filename.c_str(), e.what());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//==================================================================
|
|
|
|
|
void CPeopleList::saveContactGroups()
|
|
|
|
|
{
|
|
|
|
|
const std::string filename = CInterfaceManager::getInstance()->getSaveFileName("contactgroups", "xml");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
COFile fd;
|
|
|
|
|
if (fd.open(filename, false, false, true))
|
|
|
|
|
{
|
|
|
|
|
COXml stream;
|
|
|
|
|
stream.init(&fd);
|
|
|
|
|
|
|
|
|
|
xmlDocPtr doc = stream.getDocument();
|
|
|
|
|
xmlNodePtr node = xmlNewDocNode(doc, NULL, (const xmlChar*)"contact_groups", NULL);
|
|
|
|
|
xmlDocSetRootElement(doc, node);
|
|
|
|
|
|
|
|
|
|
for (uint k = 0; k < _Peoples.size(); ++k)
|
|
|
|
|
{
|
|
|
|
|
xmlNodePtr newNode = xmlNewChild(node, NULL, (const xmlChar*)"contact", NULL);
|
|
|
|
|
|
|
|
|
|
xmlSetProp(newNode, (const xmlChar*)"name", (const xmlChar*)_Peoples[k].getName().toString().c_str());
|
|
|
|
|
xmlSetProp(newNode, (const xmlChar*)"group", (const xmlChar*)_Peoples[k].Group.toString().c_str());
|
|
|
|
|
}
|
|
|
|
|
stream.flush();
|
|
|
|
|
fd.close();
|
|
|
|
|
}
|
|
|
|
|
nlinfo("save %s", filename.c_str());
|
|
|
|
|
}
|
|
|
|
|
catch (const Exception &e)
|
|
|
|
|
{
|
|
|
|
|
nlwarning("Error while writing the file %s : %s", filename.c_str(), e.what());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//==================================================================
|
|
|
|
|
void CPeopleList::displayLocalPlayerTell(const ucstring &receiver, uint index, const ucstring &msg,uint numBlinks /*=0*/)
|
|
|
|
|
{
|
|
|
|
|