Exemplo n.º 1
0
//************************************************************************
// removes a contact from the list
//************************************************************************
void CContactList::RemoveContact(HANDLE hContact) {
	CListContainer<CContactListEntry*,CContactListGroup*> *pGroup = NULL;
	
	///tstring strGroup = GetContactGroupPath(hContact);

	CListEntry<CContactListEntry*,CContactListGroup*> *pContactEntry = FindContact(hContact);
	if(!pContactEntry) {
		return;
	}

	if( !CConfig::GetBoolSetting(CLIST_USEGROUPS)){
		if(pContactEntry->GetType() == ITEM)
			RemoveItem(((CListItem<CContactListEntry*,CContactListGroup*>*)pContactEntry)->GetItemData());
		else
			RemoveGroup(((CListContainer<CContactListEntry*,CContactListGroup*>*)pContactEntry)->GetGroupData());
	} else {
		pGroup = (CListContainer<CContactListEntry*,CContactListGroup*>*)pContactEntry->GetParent();
		ASSERT(pGroup != NULL);
		
		CContactListEntry *pEntry = GetContactData(pContactEntry);
		if(!pEntry) {
			return;
		}
		// Update the contacts group if it has one
		if(pGroup->GetType() != ROOT)
		{
			if(!CAppletManager::IsSubContact(hContact) && pEntry->iStatus != ID_STATUS_OFFLINE)
				ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,-1);
			
			if(!CAppletManager::IsSubContact(hContact) && pEntry->iMessages > 0)
				ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,0,-pEntry->iMessages);
		}

		if(pContactEntry->GetType() == ITEM)
			pGroup->RemoveItem(((CListItem<CContactListEntry*,CContactListGroup*>*)pContactEntry)->GetItemData());
		else {
			pGroup->RemoveGroup(((CListContainer<CContactListEntry*,CContactListGroup*>*)pContactEntry)->GetGroupData());
			// Reenumerate all subcontacts (maybe MetaContacts was disabled
			int numContacts = CallService(MS_MC_GETNUMCONTACTS,(WPARAM)hContact,0);
			HANDLE hSubContact = NULL;
			for(int i=0;i<numContacts;i++) {
				hSubContact = (HANDLE *) CallService(MS_MC_GETSUBCONTACT,(WPARAM)hContact, (LPARAM)i);
				if(!FindContact(hSubContact)) {
					AddContact(hSubContact);
				}
			}
		}

		CListContainer<CContactListEntry*,CContactListGroup*> *pParent = (CListContainer<CContactListEntry*,CContactListGroup*>*)pGroup->GetParent();
		while(pParent != NULL && pGroup->IsEmpty() && !pGroup->GetGroupData()->hMetaContact)
		{
			pParent->RemoveGroup(pGroup->GetGroupData());
			pGroup = pParent;
			pParent = (CListContainer<CContactListEntry*,CContactListGroup*>*)pGroup->GetParent();
		}
	}
}
Exemplo n.º 2
0
//************************************************************************
// updates the message count for the specified contact
//************************************************************************
void CContactList::UpdateMessageCounter(CListEntry<CContactListEntry*,CContactListGroup*> *pContactEntry)
{
	CContactListEntry *pEntry = GetContactData(pContactEntry);
	if(!pEntry) {
		return;
	}
	int iOldMessages = pEntry->iMessages;

	bool bSort = false;
	HANDLE hEvent= NULL;

	hEvent = db_event_firstUnread(pEntry->hHandle);
	if(CAppletManager::IsMessageWindowOpen(pEntry->hHandle) || (hEvent == NULL && pEntry->iMessages > 0))
	{
		pEntry->iMessages = 0;
		bSort = true;
	}
	else
	{
		pEntry->iMessages = 0;
		HANDLE hLastEvent = db_event_last(pEntry->hHandle);
		while(hLastEvent != NULL && hEvent != NULL)
		{
			pEntry->iMessages++;
			if(hLastEvent == hEvent)
				break;
			hLastEvent = db_event_prev(hLastEvent);
		}
	}
	if(pEntry->iMessages >= 100)
		pEntry->strMessages = _T(">99");
	else
	{
		char buffer[8];
		buffer[0] = 0;
		itoa(pEntry->iMessages,buffer,10);
		pEntry->strMessages = toTstring(buffer);
	}

	CListContainer<CContactListEntry*,CContactListGroup*>* pContainer = ((CListContainer<CContactListEntry*,CContactListGroup*>*)pContactEntry->GetParent());
	// Update the contacts group if it has one
	if(pContainer->GetType() != ROOT)
	{
		// Update the groups event count
		if(iOldMessages != 0 && pEntry->iMessages == 0)
			ChangeGroupObjectCounters(pContainer->GetGroupData()->strPath,0,0,-1);
		else if(iOldMessages == 0 && pEntry->iMessages != 0)
			ChangeGroupObjectCounters(pContainer->GetGroupData()->strPath,0,0,1);
		else
			return;
		
		// sort the groups parent
		((CListContainer<CContactListEntry*,CContactListGroup*>*)pContainer->GetParent())->sort(CContactList::CompareEntries);
	}
}
Exemplo n.º 3
0
//************************************************************************
// called when a contacts status has changed
//************************************************************************
void CContactList::OnStatusChange(MCONTACT hContact,int iStatus)
{
	// find the entry in the list
	CListEntry<CContactListEntry *,CContactListGroup*> *pContactEntry = FindContact(hContact);
	if(!pContactEntry)
	{
		AddContact(hContact);
		return;
	}
	
	
	CContactListEntry *pItemData = GetContactData(pContactEntry);
	if(!pItemData) {
		return;
	}
	// get the old status
	int iOldStatus = pItemData->iStatus;
		
	// Update the list entry
	TCHAR *szStatus = pcli->pfnGetStatusModeDescription(iStatus, 0);
	if(szStatus != NULL)
		pItemData->strStatus =toTstring(szStatus);
	
	pItemData->iStatus = iStatus;
	
	// update the contacts group
	CListContainer<CContactListEntry*,CContactListGroup*>* pGroup = ((CListContainer<CContactListEntry*,CContactListGroup*>*)pContactEntry->GetParent());
	if(pGroup->GetType() != ROOT)
	{
		if(!db_mc_isSub(hContact) && iStatus == ID_STATUS_OFFLINE && iOldStatus != ID_STATUS_OFFLINE)
			ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,-1);

		else if(!db_mc_isSub(hContact) && iStatus != ID_STATUS_OFFLINE && iOldStatus == ID_STATUS_OFFLINE)
			ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,1);
	}
	
	// check if the entry is still visible
	if(!IsVisible(pItemData))
	{
		RemoveContact(hContact);
		return;
	}

	// sort the list
	pGroup->sort(CContactList::CompareEntries);

}
Exemplo n.º 4
0
//************************************************************************
// called when a contacts status has changed
//************************************************************************
void CContactList::OnStatusChange(HANDLE hContact,int iStatus)
{
	// find the entry in the list
	CListEntry<CContactListEntry *,CContactListGroup*> *pContactEntry = FindContact(hContact);
	if(!pContactEntry)
	{
		AddContact(hContact);
		return;
	}
	
	
	CContactListEntry *pItemData = GetContactData(pContactEntry);
	if(!pItemData) {
		return;
	}
	// get the old status
	int iOldStatus = pItemData->iStatus;
		
	// Update the list entry
	char *szStatus = (char *) CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, iStatus, 0);
	if(szStatus != NULL)
		pItemData->strStatus =toTstring(szStatus);
	
	pItemData->iStatus = iStatus;
	
	// update the contacts group
	CListContainer<CContactListEntry*,CContactListGroup*>* pGroup = ((CListContainer<CContactListEntry*,CContactListGroup*>*)pContactEntry->GetParent());
	if(pGroup->GetType() != ROOT)
	{
		if(!CAppletManager::IsSubContact(hContact) && iStatus == ID_STATUS_OFFLINE && iOldStatus != ID_STATUS_OFFLINE)
			ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,-1);

		else if(!CAppletManager::IsSubContact(hContact) && iStatus != ID_STATUS_OFFLINE && iOldStatus == ID_STATUS_OFFLINE)
			ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,1);
	}
	
	// check if the entry is still visible
	if(!IsVisible(pItemData))
	{
		RemoveContact(hContact);
		return;
	}

	// sort the list
	pGroup->sort(CContactList::CompareEntries);

}
Exemplo n.º 5
0
//************************************************************************
// initializes the group objects
//************************************************************************
void CContactList::InitializeGroupObjects()
{
	UninitializeGroupObjects();

	int res = 0;
	CContactListGroup *pGroup = NULL;
	
	HANDLE hContact =  db_find_first();
	HANDLE hMetaContact = NULL;
	char *szProto = NULL;
	while(hContact != NULL)
	{
		tstring strGroup = GetContactGroupPath(hContact);
		szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,(UINT)hContact,0);
		if(szProto && db_get_b(NULL,"MetaContacts","Enabled",1) && !stricmp(szProto,"MetaContacts"))
		{
			tstring strName = CAppletManager::GetContactDisplayname(hContact);
			tstring strPath = _T("");
			if(CConfig::GetBoolSetting(CLIST_USEGROUPS))
				strPath += strGroup;
			strPath += (strPath.empty()?_T(""):_T("\\")) + strName;

			pGroup = CreateGroupObjectByPath(strPath);	
			pGroup->hMetaContact = hContact;

			if(!strGroup.empty())
				ChangeGroupObjectCounters(strGroup,1);
		}
		// If the contact has no group, continue
		else if(!strGroup.empty() && CConfig::GetBoolSetting(CLIST_USEGROUPS))
		{
			pGroup = GetGroupObjectByPath(strGroup);	

			// create the group
			if(!pGroup)
				pGroup = CreateGroupObjectByPath(strGroup);

			// update it's counters
			if(!CAppletManager::IsSubContact(hContact))
				ChangeGroupObjectCounters(strGroup,1);
		}

        hContact = db_find_next(hContact);
    }
}
Exemplo n.º 6
0
//************************************************************************
// initializes the group objects
//************************************************************************
void CContactList::InitializeGroupObjects()
{
	UninitializeGroupObjects();

	int res = 0;
	CContactListGroup *pGroup = NULL;
	
	
	HANDLE hMetaContact = NULL;
	char *szProto = NULL;
	for(MCONTACT hContact =  db_find_first();hContact != NULL;hContact = db_find_next(hContact))
	{
		tstring strGroup = GetContactGroupPath(hContact);
		szProto = GetContactProto(hContact);
		if(szProto && db_get_b(NULL,META_PROTO,"Enabled",1) && !mir_strcmpi(szProto,META_PROTO))
		{
			tstring strName = CAppletManager::GetContactDisplayname(hContact);
			tstring strPath = _T("");
			if(CConfig::GetBoolSetting(CLIST_USEGROUPS))
				strPath += strGroup;
			strPath += (strPath.empty()?_T(""):_T("\\")) + strName;

			pGroup = CreateGroupObjectByPath(strPath);	
			pGroup->hMetaContact = hContact;

			if(!strGroup.empty())
				ChangeGroupObjectCounters(strGroup,1);
		}
		// If the contact has no group, continue
		else if(!strGroup.empty() && CConfig::GetBoolSetting(CLIST_USEGROUPS))
		{
			pGroup = GetGroupObjectByPath(strGroup);	

			// create the group
			if(!pGroup)
				pGroup = CreateGroupObjectByPath(strGroup);

			// update it's counters
			if(!db_mc_isSub(hContact))
				ChangeGroupObjectCounters(strGroup,1);
		}
    }
}
Exemplo n.º 7
0
//************************************************************************
// called when a contact has been added
//************************************************************************
void CContactList::OnContactAdded(MCONTACT hContact)
{
	// Update the list
	AddContact(hContact);

	// increase the membercount of the new group, and check if it needs to be created
	tstring strGroup = GetContactGroupPath(hContact);
	if(!strGroup.empty())
	{
		CContactListGroup *pGroup = GetGroupObjectByPath(strGroup);
		if(!pGroup)
			pGroup = CreateGroupObjectByPath(strGroup);
		
		if(!db_mc_isSub(hContact))
			ChangeGroupObjectCounters(strGroup,1);
	}
}
Exemplo n.º 8
0
//************************************************************************
// called when a contact has been deleted
//************************************************************************
void CContactList::OnContactDeleted(MCONTACT hContact)
{
	// Update the list
	RemoveContact(hContact);

	// Decrease the membercount of the old group, and check if it needs to be deleted
	int res = 0;
	tstring strGroup = GetContactGroupPath(hContact);
	if(!strGroup.empty())
	{
		CContactListGroup *pGroup = GetGroupObjectByPath(strGroup);
		
		
		if(!db_mc_isSub(hContact))
			ChangeGroupObjectCounters(strGroup,-1);
		
		if(pGroup->iMembers <= 0)
			DeleteGroupObjectByPath(pGroup->strPath);
	}
}
Exemplo n.º 9
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);
}
Exemplo n.º 10
0
//************************************************************************
// adds a contact to the list
//************************************************************************
void CContactList::AddContact(MCONTACT hContact)
{
	CListContainer<CContactListEntry*,CContactListGroup*> *pGroup = NULL;

	tstring strName = CAppletManager::GetContactDisplayname(hContact);
	char *szProto = GetContactProto(hContact);
	
	tstring strGroup = GetContactGroupPath(hContact);
	// ignore contacts without a valid protocoll
	if(szProto == NULL)
		return;

	int iStatus = db_get_w(hContact,szProto,"Status",ID_STATUS_OFFLINE);
	TCHAR *szStatus = pcli->pfnGetStatusModeDescription(iStatus, 0);

	CContactListEntry *psContact = new CContactListEntry();

	psContact->strName = strName;
	psContact->iMessages = 0;
	psContact->hHandle = hContact;
	
	psContact->iStatus = iStatus;
	
	if(szStatus != NULL)
		psContact->strStatus =toTstring(szStatus);
	psContact->strProto = toTstring(szProto);

	// check wether the contact should be listed
	if(!IsVisible(psContact)) {
		delete psContact;
		return;
	}

	// Don't add metacontacts as contacts
	if(!mir_strcmpi(szProto,"MetaContacts"))
	{
		if(!CConfig::GetBoolSetting(CLIST_USEGROUPS))
			strGroup = _T("");
		strGroup += (strGroup.empty()?_T(""):_T("\\"))+psContact->strName;
		pGroup = GetGroupByString(strGroup);
		if(pGroup == NULL)
			pGroup = AddGroupByString(strGroup);
		pGroup->GetGroupData()->hMetaContact = hContact;
		pGroup->GetGroupData()->pContactListEntry = psContact;

		pGroup = (CListContainer<CContactListEntry*,CContactListGroup*>*)pGroup->GetParent();
		if(pGroup->GetType() != ROOT && iStatus != ID_STATUS_OFFLINE)
			ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,1);

		pGroup->sort(CContactList::CompareEntries);

		// check that all subcontacts exist
		int numContacts = db_mc_getSubCount(hContact);
		MCONTACT hSubContact = NULL;
		for(int i=0;i<numContacts;i++) {
			hSubContact = db_mc_getSub(hContact, i);
			RemoveContact(hSubContact);
			AddContact(hSubContact);
		}
		return;
	}
	else if(db_mc_isSub(hContact)) {
		MCONTACT hMetaContact = db_mc_getMeta(hContact);
		// check that the metacontact exists
		if(!FindContact(hMetaContact))
			AddContact(hMetaContact);
	}

	CListItem<CContactListEntry*,CContactListGroup*> *pItem = NULL;
	if((!db_mc_isSub(hContact) && !CConfig::GetBoolSetting(CLIST_USEGROUPS)) || strGroup.empty())
	{
		pItem = AddItem(psContact);
		((CListContainer<CContactListEntry*,CContactListGroup*>*)this)->sort(CContactList::CompareEntries);
	}
	else
	{
		pGroup = GetGroupByString(strGroup);
		if(pGroup == NULL) {
			pGroup = AddGroupByString(strGroup);
		}
		pItem = pGroup->AddItem(psContact);
	
		if(!db_mc_isSub(hContact) && iStatus != ID_STATUS_OFFLINE)
			ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,1);

		pGroup->sort(CContactList::CompareEntries);
	}

	UpdateMessageCounter((CListEntry<CContactListEntry*,CContactListGroup*>*)pItem);
}
Exemplo n.º 11
0
//************************************************************************
// adds a contact to the list
//************************************************************************
void CContactList::AddContact(HANDLE hContact)
{
	CListContainer<CContactListEntry*,CContactListGroup*> *pGroup = NULL;

	tstring strName = CAppletManager::GetContactDisplayname(hContact);
	char *szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,(UINT)hContact,0);
	
	tstring strGroup = GetContactGroupPath(hContact);
	// ignore contacts without a valid protocoll
	if(szProto == NULL)
		return;

	int iStatus = db_get_w(hContact,szProto,"Status",ID_STATUS_OFFLINE);
	char *szStatus = (char *) CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, iStatus, 0);

	CContactListEntry *psContact = new CContactListEntry();

	psContact->strName = strName;
	psContact->iMessages = 0;
	psContact->hHandle = hContact;
	
	psContact->iStatus = iStatus;
	
	if(szStatus != NULL)
		psContact->strStatus =toTstring(szStatus);
	psContact->strProto = toTstring(szProto);

	// check wether the contact should be listed
	if(!IsVisible(psContact)) {
		delete psContact;
		return;
	}

	// Don't add metacontacts as contacts
	if(!stricmp(szProto,"MetaContacts"))
	{
		if(!CConfig::GetBoolSetting(CLIST_USEGROUPS))
			strGroup = _T("");
		strGroup += (strGroup.empty()?_T(""):_T("\\"))+psContact->strName;
		pGroup = GetGroupByString(strGroup);
		if(pGroup == NULL)
			pGroup = AddGroupByString(strGroup);
		pGroup->GetGroupData()->hMetaContact = hContact;
		pGroup->GetGroupData()->pContactListEntry = psContact;

		pGroup = (CListContainer<CContactListEntry*,CContactListGroup*>*)pGroup->GetParent();
		if(pGroup->GetType() != ROOT && iStatus != ID_STATUS_OFFLINE)
			ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,1);

		pGroup->sort(CContactList::CompareEntries);

		// check that all subcontacts exist
		int numContacts = CallService(MS_MC_GETNUMCONTACTS,(WPARAM)hContact,0);
		HANDLE hSubContact = NULL;
		for(int i=0;i<numContacts;i++) {
			hSubContact = (HANDLE *) CallService(MS_MC_GETSUBCONTACT, (WPARAM)hContact, (LPARAM)i);
			RemoveContact(hSubContact);
			AddContact(hSubContact);
		}
		return;
	} else if(CAppletManager::IsSubContact(hContact)) {
		HANDLE hMetaContact = (HANDLE *) CallService(MS_MC_GETMETACONTACT, (WPARAM)hContact, 0);
		// check that the metacontact exists
		if(!FindContact(hMetaContact)) {
			AddContact(hMetaContact);
		}
	}

	CListItem<CContactListEntry*,CContactListGroup*> *pItem = NULL;
	if((!CAppletManager::IsSubContact(hContact) && !CConfig::GetBoolSetting(CLIST_USEGROUPS)) || strGroup.empty())
	{
		pItem = AddItem(psContact);
		((CListContainer<CContactListEntry*,CContactListGroup*>*)this)->sort(CContactList::CompareEntries);
	}
	else
	{
		pGroup = GetGroupByString(strGroup);
		if(pGroup == NULL) {
			pGroup = AddGroupByString(strGroup);
		}
		pItem = pGroup->AddItem(psContact);
	
		if(!CAppletManager::IsSubContact(hContact) && iStatus != ID_STATUS_OFFLINE)
			ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,1);

		pGroup->sort(CContactList::CompareEntries);
	}

	UpdateMessageCounter((CListEntry<CContactListEntry*,CContactListGroup*>*)pItem);
}