BOOL SM_RemoveAll (void) { while (m_WndList) { SESSION_INFO *pLast = m_WndList->next; if(m_WndList->hWnd) { SendMessage(m_WndList->hWnd, GC_EVENT_CONTROL+WM_USER+500, SESSION_TERMINATE, 2); } DoEventHook(m_WndList->pszID, m_WndList->pszModule, GC_SESSION_TERMINATE, NULL, NULL, (DWORD)m_WndList->dwItemData); if(m_WndList->hContact) CList_SetOffline(m_WndList->hContact, m_WndList->iType == GCW_CHATROOM?TRUE:FALSE); DBWriteContactSettingString(m_WndList->hContact, m_WndList->pszModule , "Topic", ""); DBDeleteContactSetting(m_WndList->hContact, "CList", "StatusMsg"); DBWriteContactSettingString(m_WndList->hContact, m_WndList->pszModule, "StatusBar", ""); UM_RemoveAll(&m_WndList->pUsers); TM_RemoveAll(&m_WndList->pStatuses); LM_RemoveAll(&m_WndList->pLog, &m_WndList->pLogEnd); m_WndList->iStatusCount = 0; m_WndList->nUsersInNicklist = 0; free (m_WndList->pszID); free (m_WndList->pszModule); if(m_WndList->pszName) free(m_WndList->pszName); if(m_WndList->pszStatusbarText) free(m_WndList->pszStatusbarText); if(m_WndList->pszTopic) free(m_WndList->pszTopic); while (m_WndList->lpCommands != NULL) { COMMAND_INFO *pNext = m_WndList->lpCommands->next; free(m_WndList->lpCommands->lpCommand); free(m_WndList->lpCommands); m_WndList->lpCommands = pNext; } free (m_WndList); m_WndList = pLast; } m_WndList = NULL; return TRUE; }
int SM_RemoveSession( const TCHAR* pszID, const char* pszModule) { SESSION_INFO *pTemp = m_WndList, *pLast = NULL; if (!pszModule) return FALSE; while (pTemp != NULL) { if ((!pszID && pTemp->iType != GCW_SERVER || !lstrcmpi(pTemp->ptszID,pszID)) && !lstrcmpiA(pTemp->pszModule,pszModule)) // match { COMMAND_INFO *pCurComm; DWORD dw = pTemp->dwItemData; if (!g_Settings.TabsEnable) { if (pTemp->hWnd ) SendMessage(pTemp->hWnd, GC_EVENT_CONTROL+WM_USER+500, SESSION_TERMINATE, 0); } else { if (g_TabSession.hWnd) SendMessage(g_TabSession.hWnd, GC_REMOVETAB, 1, (LPARAM)pTemp); } if (pTemp->hWnd) g_TabSession.nUsersInNicklist = 0; DoEventHook(pTemp->ptszID, pTemp->pszModule, GC_SESSION_TERMINATE, NULL, NULL, (DWORD)pTemp->dwItemData); if (pLast == NULL) m_WndList = pTemp->next; else pLast->next = pTemp->next; UM_RemoveAll(&pTemp->pUsers); TM_RemoveAll(&pTemp->pStatuses); LM_RemoveAll(&pTemp->pLog, &pTemp->pLogEnd); pTemp->iStatusCount = 0; pTemp->nUsersInNicklist = 0; // contact may have been deleted here already, since function may be called after deleting // contact so the handle may be invalid, therefore DBGetContactSettingByte shall return 0 if (pTemp->hContact && DBGetContactSettingByte( pTemp->hContact, pTemp->pszModule, "ChatRoom", 0 ) != 0) { CList_SetOffline(pTemp->hContact, pTemp->iType == GCW_CHATROOM?TRUE:FALSE); /* if (pTemp->iType != GCW_SERVER) DBWriteContactSettingByte(pTemp->hContact, "CList", "Hidden", 1);*/ DBWriteContactSettingString(pTemp->hContact, pTemp->pszModule, "Topic", ""); DBWriteContactSettingString(pTemp->hContact, pTemp->pszModule, "StatusBar", ""); DBDeleteContactSetting(pTemp->hContact, "CList", "StatusMsg"); } mir_free( pTemp->pszModule ); mir_free( pTemp->ptszID ); mir_free( pTemp->ptszName ); mir_free( pTemp->ptszStatusbarText ); mir_free( pTemp->ptszTopic ); #if defined( _UNICODE ) mir_free( pTemp->pszID ); mir_free( pTemp->pszName ); #endif // delete commands pCurComm = pTemp->lpCommands; while (pCurComm != NULL) { COMMAND_INFO *pNext = pCurComm->next; mir_free(pCurComm->lpCommand); mir_free(pCurComm); pCurComm = pNext; } mir_free(pTemp); if (pszID) return (int)dw; if (pLast) pTemp = pLast->next; else pTemp = m_WndList; } else { pLast = pTemp; pTemp = pTemp->next; } } return FALSE; }
static INT_PTR DoControl(GCEVENT * gce, WPARAM wp) { if ( gce->pDest->iType == GC_EVENT_CONTROL ) { switch (wp) { case WINDOW_HIDDEN: { SESSION_INFO* si = SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule); if (si) { si->bInitDone = TRUE; SetActiveSession(si->ptszID, si->pszModule); if (si->hWnd) ShowRoom(si, wp, FALSE); } } return 0; case WINDOW_MINIMIZE: case WINDOW_MAXIMIZE: case WINDOW_VISIBLE: case SESSION_INITDONE: { SESSION_INFO* si = SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule); if (si) { si->bInitDone = TRUE; if (wp != SESSION_INITDONE || DBGetContactSettingByte(NULL, "Chat", "PopupOnJoin", 0) == 0) ShowRoom(si, wp, TRUE); return 0; } } break; case SESSION_OFFLINE: SM_SetOffline(gce->pDest->ptszID, gce->pDest->pszModule); // fall through case SESSION_ONLINE: SM_SetStatus( gce->pDest->ptszID, gce->pDest->pszModule, wp==SESSION_ONLINE?ID_STATUS_ONLINE:ID_STATUS_OFFLINE); break; case WINDOW_CLEARLOG: { SESSION_INFO* si = SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule); if ( si ) { LM_RemoveAll(&si->pLog, &si->pLogEnd); si->iEventCount = 0; si->LastTime = 0; } break; } case SESSION_TERMINATE: return SM_RemoveSession(gce->pDest->ptszID, gce->pDest->pszModule); } SM_SendMessage(gce->pDest->ptszID, gce->pDest->pszModule, GC_EVENT_CONTROL + WM_USER + 500, wp, 0); } else if (gce->pDest->iType == GC_EVENT_CHUID && gce->pszText) { SM_ChangeUID( gce->pDest->ptszID, gce->pDest->pszModule, gce->ptszNick, gce->ptszText); } else if (gce->pDest->iType == GC_EVENT_CHANGESESSIONAME && gce->pszText) { SESSION_INFO* si = SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule); if ( si ) { replaceStr( &si->ptszName, gce->ptszText ); if (si->hWnd) SendMessage(si->hWnd, DM_UPDATETITLEBAR, 0, 0); } } else if (gce->pDest->iType == GC_EVENT_SETITEMDATA) { SESSION_INFO* si = SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule); if (si) si->dwItemData = gce->dwItemData; } else if (gce->pDest->iType ==GC_EVENT_GETITEMDATA) { SESSION_INFO* si = SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule); if (si) { gce->dwItemData = si->dwItemData; return si->dwItemData; } return 0; } else if (gce->pDest->iType ==GC_EVENT_SETSBTEXT) { SESSION_INFO* si = SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule); if (si) { replaceStr( &si->ptszStatusbarText, gce->ptszText ); if ( si->ptszStatusbarText ) DBWriteContactSettingTString(si->windowData.hContact, si->pszModule, "StatusBar", si->ptszStatusbarText); else DBWriteContactSettingString(si->windowData.hContact, si->pszModule, "StatusBar", ""); if (si->hWnd) { SendMessage(si->hWnd, DM_UPDATESTATUSBAR, 0, 0); } } } else if (gce->pDest->iType == GC_EVENT_ACK) { SM_SendMessage(gce->pDest->ptszID, gce->pDest->pszModule, GC_ACKMESSAGE, 0, 0); } else if (gce->pDest->iType == GC_EVENT_SENDMESSAGE && gce->pszText) { SM_SendUserMessage( gce->pDest->ptszID, gce->pDest->pszModule, gce->ptszText); } else if (gce->pDest->iType == GC_EVENT_SETSTATUSEX) { SM_SetStatusEx( gce->pDest->ptszID, gce->pDest->pszModule, gce->ptszText, gce->dwItemData); } else return 1; return 0; }
int SM_RemoveSession(const TCHAR* pszID, const char* pszModule, bool removeContact) { SESSION_INFO* pTemp = m_WndList, *pLast = NULL; if (!pszModule) return FALSE; while (pTemp != NULL) { if ((!pszID && pTemp->iType != GCW_SERVER || !lstrcmpi(pTemp->ptszID, pszID)) && !lstrcmpiA(pTemp->pszModule, pszModule)) { // match COMMAND_INFO *pCurComm; DWORD dw = pTemp->dwItemData; if (pTemp->hWnd) SendMessage(pTemp->hWnd, GC_EVENT_CONTROL + WM_USER + 500, SESSION_TERMINATE, 0); DoEventHook(pTemp->ptszID, pTemp->pszModule, GC_SESSION_TERMINATE, NULL, NULL, (DWORD)pTemp->dwItemData); if (pLast == NULL) m_WndList = pTemp->next; else pLast->next = pTemp->next; UM_RemoveAll(&pTemp->pUsers); TM_RemoveAll(&pTemp->pStatuses); LM_RemoveAll(&pTemp->pLog, &pTemp->pLogEnd); pTemp->iStatusCount = 0; pTemp->nUsersInNicklist = 0; if (pTemp->hContact) { CList_SetOffline(pTemp->hContact, pTemp->iType == GCW_CHATROOM ? TRUE : FALSE); //if (pTemp->iType != GCW_SERVER) //DBWriteContactSettingByte(pTemp->hContact, "CList", "Hidden", 1); } DBWriteContactSettingString(pTemp->hContact, pTemp->pszModule , "Topic", ""); DBWriteContactSettingString(pTemp->hContact, pTemp->pszModule, "StatusBar", ""); DBDeleteContactSetting(pTemp->hContact, "CList", "StatusMsg"); if (removeContact) CallService(MS_DB_CONTACT_DELETE, (WPARAM)pTemp->hContact, 0); mir_free(pTemp->pszModule); mir_free(pTemp->ptszID); mir_free(pTemp->ptszName); mir_free(pTemp->ptszStatusbarText); mir_free(pTemp->ptszTopic); mir_free(pTemp->pszID); mir_free(pTemp->pszName); // delete commands pCurComm = pTemp->lpCommands; while (pCurComm != NULL) { COMMAND_INFO *pNext = pCurComm->next; mir_free(pCurComm->lpCommand); mir_free(pCurComm); pCurComm = pNext; } mir_free(pTemp); if (pszID) return (int)dw; if (pLast) pTemp = pLast->next; else pTemp = m_WndList; } else { pLast = pTemp; pTemp = pTemp->next; } } return FALSE; }