//************************************************************************ // 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); } }
//************************************************************************ // 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); } }
//************************************************************************ // 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); } } }
//************************************************************************ // 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); } }
//************************************************************************ // called when a contacts nickname has changed //************************************************************************ void CContactList::OnContactNickChanged(MCONTACT hContact, tstring strNick) { CListEntry<CContactListEntry *,CContactListGroup*> *pContactEntry = FindContact(hContact); if(!pContactEntry) return; if(pContactEntry->GetType() == CONTAINER) { CListContainer *pGroup = ((CListContainer<CContactListEntry*,CContactListGroup*>*)pContactEntry); pGroup->GetGroupData()->strName = strNick; tstring strPath = GetContactGroupPath(hContact); pGroup->GetGroupData()->strPath = strPath + (strPath.empty()?_T(""):_T("\\")) + strNick; } CContactListEntry* pEntry = GetContactData(pContactEntry); if(!pEntry) { return; } pEntry->strName = strNick; ((CListContainer<CContactListEntry*,CContactListGroup*>*)pContactEntry->GetParent())->sort(CContactList::CompareEntries); }
//************************************************************************ // 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); }
//************************************************************************ // 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); }
//************************************************************************ // 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); }