Exemple #1
0
//************************************************************************
// Adds a group
//************************************************************************
CListContainer<CContactListEntry*,CContactListGroup*> *CContactList::AddGroupByString(tstring strGroup)
{
	tstring strParse = strGroup;
	tstring strPath = _T("");

	CListContainer<CContactListEntry*,CContactListGroup*> *pGroup = (CListContainer<CContactListEntry*,CContactListGroup*>*)this;
	CListContainer<CContactListEntry*,CContactListGroup*> *pGroup2 = NULL;
	tstring::size_type pos;
	while((pos = strParse.find('\\')) !=  tstring::npos )
	{
		strGroup = strParse.substr(0,pos);
		strParse = strParse.substr(pos+1);
		strPath += strGroup;

		if(pGroup2 = FindGroupInGroup(strGroup,pGroup))
			pGroup = pGroup2;
		else
		{
			CContactListGroup *pGroupObject = GetGroupObjectByPath(strPath);
			if(!pGroupObject)
				pGroupObject = CreateGroupObjectByPath(strPath);
			pGroup2 = pGroup->InsertGroup(pGroup->begin(),pGroupObject);
			pGroup->sort(CContactList::CompareEntries);
			pGroup = pGroup2;
		}
		ASSERT(pGroup != NULL);
		strPath += _T("\\");
	}
	strPath += strParse;
	if(pGroup2 = FindGroupInGroup(strParse,pGroup))
		return pGroup2;
	else
	{
		CContactListGroup *pGroupObject = GetGroupObjectByPath(strPath);
		if(!pGroupObject)
			pGroupObject = CreateGroupObjectByPath(strPath);
		pGroup2 = pGroup->InsertGroup(pGroup->begin(),pGroupObject);
		pGroup->sort(CContactList::CompareEntries);
		return pGroup2;
	}
}
Exemple #2
0
//************************************************************************
// called when a contacts group has changed
//************************************************************************
void CContactList::OnContactGroupChanged(MCONTACT hContact,tstring strGroup)
{
	bool bMetaContact = false;
	

	strGroup = GetContactGroupPath(hContact);

	// Decrease the membercount of the old group
	CListEntry<CContactListEntry *,CContactListGroup*> *pContactEntry = FindContact(hContact);
	CContactListGroup *pOldGroup = NULL;
	// If the contactentry was not found, try adding the contact (metacontacts fix)
	if(!pContactEntry) {
		return;
	}
	if(pContactEntry->GetType() == CONTAINER)
		bMetaContact = true;


	CListContainer<CContactListEntry*,CContactListGroup*>* pContainer = ((CListContainer<CContactListEntry*,CContactListGroup*>*)pContactEntry->GetParent());
	// Update the contacts group if it has one
	if(pContainer->GetType() != ROOT)
	{
		pOldGroup = pContainer->GetGroupData();
		if(!db_mc_isSub(hContact))
			ChangeGroupObjectCounters(pOldGroup->strPath,-1);
	}
	
	// increase the membercount of the new group, and check if it needs to be created
	if(!strGroup.empty())
	{
		CContactListGroup *pGroup = GetGroupObjectByPath(strGroup);
		if(!pGroup)
			pGroup = CreateGroupObjectByPath(strGroup);
		if(!db_mc_isSub(hContact))
			ChangeGroupObjectCounters(strGroup,1);
	}

	// move subcontacts
	if(pContactEntry->GetType() == CONTAINER)
	{
		CListContainer<CContactListEntry*,CContactListGroup*> *pGroup = (CListContainer<CContactListEntry*,CContactListGroup*>*)pContactEntry;
		CListContainer<CContactListEntry*,CContactListGroup*>::iterator iter = pGroup->begin();
		while(!pGroup->empty())
		{
			iter = pGroup->begin();
			if((*iter)->GetType() == ITEM)
				OnContactGroupChanged(GetContactData(*iter)->hHandle,_T(""));
			Sleep(1);
		}
	}

	// update the list
	RemoveContact(hContact);
	AddContact(hContact);

	if(bMetaContact)
	{
		tstring strName = CAppletManager::GetContactDisplayname(hContact);
		tstring strPath = _T("");
		if(pOldGroup)
			strPath += pOldGroup->strPath;
		strPath += (strPath.empty()?_T(""):_T("\\")) + strName;
		DeleteGroupObjectByPath(strPath);
	}

	// check if the old group ( if it exists ) needs to be deleted
	if(pOldGroup && !pOldGroup->hMetaContact && pOldGroup->iMembers <= 0 && pOldGroup->iGroups <= 0)
		DeleteGroupObjectByPath(pOldGroup->strPath);
}