From cb433a48f6562a49695f77ea2e39f8a5592c8822 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 20 Mar 2014 19:29:01 +0000 Subject: disabling metacontacts: fixes git-svn-id: http://svn.miranda-ng.org/main/trunk@8668 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Scriver/src/globals.cpp | 8 +-- plugins/Scriver/src/msgs.cpp | 9 ++- plugins/TabSRMM/src/mim.cpp | 12 ++-- src/core/stdmsg/src/cmdlist.cpp | 97 ++++++++---------------------- src/core/stdmsg/src/cmdlist.h | 18 +----- src/core/stdmsg/src/globals.cpp | 9 ++- src/core/stdmsg/src/msgdialog.cpp | 34 +++++------ src/core/stdmsg/src/msgs.h | 6 +- src/mir_core/mc.cpp | 6 +- src/modules/metacontacts/meta_services.cpp | 15 ++--- 10 files changed, 81 insertions(+), 133 deletions(-) diff --git a/plugins/Scriver/src/globals.cpp b/plugins/Scriver/src/globals.cpp index dc06318c27..29ecedf337 100644 --- a/plugins/Scriver/src/globals.cpp +++ b/plugins/Scriver/src/globals.cpp @@ -392,17 +392,17 @@ void ReloadGlobals() static int ackevent(WPARAM wParam, LPARAM lParam) { - ACKDATA *pAck = (ACKDATA *)lParam; + ACKDATA *pAck = (ACKDATA*)lParam; if (!pAck) return 0; if (pAck->type != ACKTYPE_MESSAGE) return 0; - MCONTACT hContact = db_mc_getMeta(pAck->hContact); - if (hContact == NULL) - hContact = pAck->hContact; + MCONTACT hContact = pAck->hContact; MessageSendQueueItem *item = FindSendQueueItem(hContact, (HANDLE)pAck->hProcess); + if (item == NULL) + item = FindSendQueueItem(hContact = db_mc_getMeta(pAck->hContact), (HANDLE)pAck->hProcess); if (item == NULL) return 0; diff --git a/plugins/Scriver/src/msgs.cpp b/plugins/Scriver/src/msgs.cpp index cbd8b96559..7b7bb06af7 100644 --- a/plugins/Scriver/src/msgs.cpp +++ b/plugins/Scriver/src/msgs.cpp @@ -91,12 +91,15 @@ static INT_PTR ReadMessageCommand(WPARAM wParam, LPARAM lParam) static int MessageEventAdded(WPARAM hContact, LPARAM lParam) { + HANDLE hDbEvent = (HANDLE)lParam; DBEVENTINFO dbei = { sizeof(dbei) }; - db_event_get((HANDLE)lParam, &dbei); + db_event_get(hDbEvent, &dbei); if (dbei.eventType == EVENTTYPE_MESSAGE && (dbei.flags & DBEF_READ)) return 0; HWND hwnd = WindowList_Find(g_dat.hMessageWindowList, hContact); + if (hwnd == NULL) + hwnd = WindowList_Find(g_dat.hMessageWindowList, hContact = db_event_getContact(hDbEvent)); if (hwnd) SendMessage(hwnd, HM_DBEVENTADDED, hContact, lParam); @@ -124,12 +127,12 @@ static int MessageEventAdded(WPARAM hContact, LPARAM lParam) CLISTEVENT cle = { sizeof(cle) }; cle.flags = CLEF_TCHAR; cle.hContact = hContact; - cle.hDbEvent = (HANDLE)lParam; + cle.hDbEvent = hDbEvent; cle.hIcon = LoadSkinnedIcon(SKINICON_EVENT_MESSAGE); cle.pszService = "SRMsg/ReadMessage"; mir_sntprintf(toolTip, SIZEOF(toolTip), TranslateT("Message from %s"), contactName); cle.ptszTooltip = toolTip; - CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)& cle); + CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cle); } return 0; } diff --git a/plugins/TabSRMM/src/mim.cpp b/plugins/TabSRMM/src/mim.cpp index d7fc9f7b20..53dcd6aa31 100644 --- a/plugins/TabSRMM/src/mim.cpp +++ b/plugins/TabSRMM/src/mim.cpp @@ -491,12 +491,14 @@ int CMimAPI::PrebuildContactMenu(WPARAM hContact, LPARAM lParam) * improve the overall responsiveness when receiving messages. */ -int CMimAPI::DispatchNewEvent(WPARAM wParam, LPARAM lParam) +int CMimAPI::DispatchNewEvent(WPARAM hContact, LPARAM lParam) { - if (wParam) { - HWND h = M.FindWindow(wParam); + if (hContact) { + HWND h = M.FindWindow(hContact); + if (h == NULL) + h = M.FindWindow(hContact = db_event_getContact((HANDLE)lParam)); if (h) - PostMessage(h, HM_DBEVENTADDED, wParam, lParam); // was SENDMESSAGE !!! XXX + PostMessage(h, HM_DBEVENTADDED, hContact, lParam); // was SENDMESSAGE !!! XXX } return 0; } @@ -520,6 +522,8 @@ int CMimAPI::MessageEventAdded(WPARAM hContact, LPARAM lParam) db_event_get(hDbEvent, &dbei); HWND hwnd = M.FindWindow(hContact); + if (hwnd == NULL) + hwnd = M.FindWindow(hContact = db_event_getContact(hDbEvent)); BOOL isCustomEvent = IsCustomEvent(dbei.eventType); BOOL isShownCustomEvent = DbEventIsForMsgWindow(&dbei); diff --git a/src/core/stdmsg/src/cmdlist.cpp b/src/core/stdmsg/src/cmdlist.cpp index b4a326a5b3..c861f12585 100644 --- a/src/core/stdmsg/src/cmdlist.cpp +++ b/src/core/stdmsg/src/cmdlist.cpp @@ -21,44 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h" -int tcmdlist_append(SortedList *list, TCHAR *data) -{ - TCmdList *new_list; - - if (!data) - return list->realCount - 1; - - if (list->realCount >= 20) - { - TCmdList* n = (TCmdList*)list->items[0]; - mir_free(n->szCmd); - mir_free(n); - List_Remove(list, 0); - } - - new_list = (TCmdList*)mir_alloc(sizeof(TCmdList)); - new_list->szCmd = mir_tstrdup(data); - - List_InsertPtr(list, new_list); - - return list->realCount - 1; -} - -void tcmdlist_free(SortedList *list) -{ - int i; - TCmdList** n = (TCmdList**)list->items; - - for (i = 0; i < list->realCount; ++i) - { - mir_free(n[i]->szCmd); - mir_free(n[i]); - } - List_Destroy(list); - mir_free(list); -} - -static SortedList msgQueue = { NULL, 0, 0, 5, NULL }; +static LIST msgQueue(5, NumericKeySortT); static CRITICAL_SECTION csMsgQueue; static UINT_PTR timerId; @@ -67,26 +30,21 @@ void MessageFailureProcess(TMsgQueue *item, const char* err); static VOID CALLBACK MsgTimer(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { int i, ntl = 0; - TMsgQueue **tmlst = NULL; + LIST arTimedOut(1); EnterCriticalSection(&csMsgQueue); - for (i = 0; i < msgQueue.realCount; ++i) - { - TMsgQueue *item = (TMsgQueue*)msgQueue.items[i]; - if (dwTime - item->ts > g_dat.msgTimeout) - { - if (!ntl) - tmlst = (TMsgQueue**)alloca((msgQueue.realCount - i) * sizeof(TMsgQueue*)); - tmlst[ntl++] = item; - - List_Remove(&msgQueue, i--); + for (i = msgQueue.getCount()-1; i >= 0; i--) { + TMsgQueue *item = msgQueue[i]; + if (dwTime - item->ts > g_dat.msgTimeout) { + arTimedOut.insert(item); + msgQueue.remove(i); } } LeaveCriticalSection(&csMsgQueue); - for (i = 0; i < ntl; ++i) - MessageFailureProcess(tmlst[i], LPGEN("The message send timed out.")); + for (i = 0; i < arTimedOut.getCount(); ++i) + MessageFailureProcess(arTimedOut[i], LPGEN("The message send timed out.")); } void msgQueue_add(MCONTACT hContact, int id, const TCHAR* szMsg, HANDLE hDbEvent) @@ -99,9 +57,9 @@ void msgQueue_add(MCONTACT hContact, int id, const TCHAR* szMsg, HANDLE hDbEvent item->ts = GetTickCount(); EnterCriticalSection(&csMsgQueue); - if (!msgQueue.realCount && !timerId) + if (!msgQueue.getCount() && !timerId) timerId = SetTimer(NULL, 0, 5000, MsgTimer); - List_InsertPtr(&msgQueue, item); + msgQueue.insert(item); LeaveCriticalSection(&csMsgQueue); } @@ -111,17 +69,16 @@ void msgQueue_processack(MCONTACT hContact, int id, BOOL success, const char* sz int i; TMsgQueue* item = NULL; + MCONTACT hMeta = db_mc_getMeta(hContact); + EnterCriticalSection(&csMsgQueue); - for (i = 0; i < msgQueue.realCount; ++i) - { - item = (TMsgQueue*)msgQueue.items[i]; - if (item->hContact == hContact && item->id == id) - { - List_Remove(&msgQueue, i); + for (i = 0; i < msgQueue.getCount(); i++) { + item = msgQueue[i]; + if ((item->hContact == hContact || item->hContact == hMeta) && item->id == id) { + msgQueue.remove(i); i--; - if (!msgQueue.realCount && timerId) - { + if (!msgQueue.getCount() && timerId) { KillTimer(NULL, timerId); timerId = 0; } @@ -131,15 +88,12 @@ void msgQueue_processack(MCONTACT hContact, int id, BOOL success, const char* sz } LeaveCriticalSection(&csMsgQueue); - if (item) - { - if (success) - { + if (item) { + if (success) { mir_free(item->szMsg); mir_free(item); } - else - MessageFailureProcess(item, szErr); + else MessageFailureProcess(item, szErr); } } @@ -150,17 +104,14 @@ void msgQueue_init(void) void msgQueue_destroy(void) { - int i; - EnterCriticalSection(&csMsgQueue); - for (i = 0; i < msgQueue.realCount; ++i) - { - TMsgQueue* item = (TMsgQueue*)msgQueue.items[i]; + for (int i = 0; i < msgQueue.getCount(); i++) { + TMsgQueue *item = msgQueue[i]; mir_free(item->szMsg); mir_free(item); } - List_Destroy(&msgQueue); + msgQueue.destroy(); LeaveCriticalSection(&csMsgQueue); diff --git a/src/core/stdmsg/src/cmdlist.h b/src/core/stdmsg/src/cmdlist.h index 66d273617c..1410d46122 100644 --- a/src/core/stdmsg/src/cmdlist.h +++ b/src/core/stdmsg/src/cmdlist.h @@ -22,28 +22,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef SRMM_CMDLIST_H #define SRMM_CMDLIST_H -typedef struct _TCmdList -{ - TCHAR *szCmd; -} -TCmdList; - -int tcmdlist_append(SortedList *list, TCHAR *data); -void tcmdlist_free(SortedList *list); - -__inline TCHAR* tcmdlist_getitem(SortedList *list, int ind) -{ return ((TCmdList*)list->items[ind])->szCmd; } - - -typedef struct _TMsgQueue +struct TMsgQueue { int id; MCONTACT hContact; TCHAR* szMsg; HANDLE hDbEvent; unsigned ts; -} -TMsgQueue; +}; void msgQueue_add(MCONTACT hContact, int id, const TCHAR* szMsg, HANDLE hDbEvent); void msgQueue_processack(MCONTACT hContact, int id, BOOL success, const char* szErr); diff --git a/src/core/stdmsg/src/globals.cpp b/src/core/stdmsg/src/globals.cpp index 56be8b56c1..f65644f92b 100644 --- a/src/core/stdmsg/src/globals.cpp +++ b/src/core/stdmsg/src/globals.cpp @@ -123,6 +123,9 @@ static int dbaddedevent(WPARAM hContact, LPARAM lParam) { if (hContact) { HWND h = WindowList_Find(g_dat.hMessageWindowList, hContact); + if (h == NULL) + h = WindowList_Find(g_dat.hMessageWindowList, hContact = db_event_getContact((HANDLE)lParam)); + if (h) SendMessage(h, HM_DBEVENTADDED, hContact, lParam); } @@ -133,11 +136,7 @@ static int ackevent(WPARAM wParam, LPARAM lParam) { ACKDATA *pAck = (ACKDATA *)lParam; if (pAck && pAck->type == ACKTYPE_MESSAGE) { - MCONTACT hContact = db_mc_getMeta(pAck->hContact); - if (hContact == NULL) - hContact = pAck->hContact; - - msgQueue_processack(hContact, (int)pAck->hProcess, pAck->result == ACKRESULT_SUCCESS, (char*)pAck->lParam); + msgQueue_processack(pAck->hContact, (int)pAck->hProcess, pAck->result == ACKRESULT_SUCCESS, (char*)pAck->lParam); if (pAck->result == ACKRESULT_SUCCESS) SkinPlaySound("SendMsg"); diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp index 1daa199bf7..9cddd03f4a 100644 --- a/src/core/stdmsg/src/msgdialog.cpp +++ b/src/core/stdmsg/src/msgdialog.cpp @@ -326,13 +326,13 @@ static LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd, UINT msg, WPARAM wPar if (wParam == VK_UP && (GetKeyState(VK_CONTROL) & 0x8000) && ((g_dat.flags & (SMF_AUTOCLOSE | SMF_CTRLSUPPORT)) == SMF_CTRLSUPPORT)) { - if (pdat->cmdList->realCount) { + if (pdat->cmdList.getCount()) { if (pdat->cmdListInd < 0) { - pdat->cmdListInd = pdat->cmdList->realCount - 1; - SetEditorText(hwnd, tcmdlist_getitem(pdat->cmdList, pdat->cmdListInd)); + pdat->cmdListInd = pdat->cmdList.getCount()-1; + SetEditorText(hwnd, pdat->cmdList[pdat->cmdListInd]); } else if (pdat->cmdListInd > 0) { - SetEditorText(hwnd, tcmdlist_getitem(pdat->cmdList, --pdat->cmdListInd)); + SetEditorText(hwnd, pdat->cmdList[--pdat->cmdListInd]); } } EnableWindow(GetDlgItem(GetParent(hwnd), IDOK), GetWindowTextLength(hwnd) != 0); @@ -342,12 +342,12 @@ static LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd, UINT msg, WPARAM wPar if (wParam == VK_DOWN && (GetKeyState(VK_CONTROL) & 0x8000) && ((g_dat.flags & (SMF_AUTOCLOSE | SMF_CTRLSUPPORT)) == SMF_CTRLSUPPORT)) { - if (pdat->cmdList->realCount && pdat->cmdListInd >= 0) { - if (pdat->cmdListInd < (pdat->cmdList->realCount - 1)) - SetEditorText(hwnd, tcmdlist_getitem(pdat->cmdList, ++pdat->cmdListInd)); + if (pdat->cmdList.getCount() && pdat->cmdListInd >= 0) { + if (pdat->cmdListInd < (pdat->cmdList.getCount()-1)) + SetEditorText(hwnd, pdat->cmdList[++pdat->cmdListInd]); else { pdat->cmdListInd = -1; - SetEditorText(hwnd, tcmdlist_getitem(pdat->cmdList, pdat->cmdList->realCount - 1)); + SetEditorText(hwnd, pdat->cmdList[pdat->cmdList.getCount()-1]); } } @@ -685,7 +685,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP { NewMessageWindowLParam *newData = (NewMessageWindowLParam *)lParam; TranslateDialogDefault(hwndDlg); - dat = (SrmmWindowData *)mir_calloc(sizeof(SrmmWindowData)); + dat = new SrmmWindowData(); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); dat->hContact = newData->hContact; @@ -717,7 +717,6 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP dat->wStatus = ID_STATUS_OFFLINE; dat->wOldStatus = dat->wStatus; dat->splitterPos = (int)db_get_dw(db_get_b(NULL, SRMMMOD, SRMSGSET_SAVEPERCONTACT, SRMSGDEFSET_SAVEPERCONTACT) ? dat->hContact : NULL, SRMMMOD, "splitterPos", (DWORD)-1); - dat->cmdList = List_Create(0, 20); dat->cmdListInd = -1; dat->nTypeMode = PROTOTYPE_SELFTYPING_OFF; SetTimer(hwndDlg, TIMERID_TYPE, 1000, NULL); @@ -1076,10 +1075,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETCHARFORMAT, SCF_ALL, (WPARAM) &cf); } - /* - * configure message history for proper RTL formatting - */ - + // configure message history for proper RTL formatting { PARAFORMAT2 pf2; ZeroMemory((void *)&pf2, sizeof(pf2)); @@ -1478,7 +1474,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP HANDLE hNewEvent = SendMessageDirect(temp, dat->hContact, dat->szProto); if (hNewEvent) { - tcmdlist_append(dat->cmdList, temp); + dat->cmdList.insert(mir_tstrdup(temp)); dat->cmdListInd = -1; if (dat->nTypeMode == PROTOTYPE_SELFTYPING_ON) @@ -1742,7 +1738,11 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP DeleteObject(dat->hBkgBrush); if (dat->hwndStatus) DestroyWindow(dat->hwndStatus); - tcmdlist_free(dat->cmdList); + + for (int i = 0; i < dat->cmdList.getCount(); i++) + mir_free(dat->cmdList[i]); + dat->cmdList.destroy(); + WindowList_Remove(g_dat.hMessageWindowList, hwndDlg); db_set_dw(db_get_b(NULL, SRMMMOD, SRMSGSET_SAVEPERCONTACT, SRMSGDEFSET_SAVEPERCONTACT) ? dat->hContact : NULL, SRMMMOD, "splitterPos", dat->splitterPos); SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_UNSUBCLASSED, 0, 0); @@ -1777,7 +1777,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP Button_FreeIcon_IcoLib(hwndDlg, IDC_HISTORY); Button_FreeIcon_IcoLib(hwndDlg, IDC_USERMENU); Window_FreeIcon_IcoLib(hwndDlg); - mir_free(dat); + delete dat; SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); break; } diff --git a/src/core/stdmsg/src/msgs.h b/src/core/stdmsg/src/msgs.h index c2f4d36e63..21357908ac 100644 --- a/src/core/stdmsg/src/msgs.h +++ b/src/core/stdmsg/src/msgs.h @@ -35,6 +35,10 @@ struct NewMessageWindowLParam struct SrmmWindowData { + SrmmWindowData() : + cmdList(20) + {} + MCONTACT hContact; HANDLE hDbEventFirst, hDbEventLast; HBRUSH hBkgBrush; @@ -60,7 +64,7 @@ struct SrmmWindowData WORD wStatus; WORD wOldStatus; int cmdListInd; - SortedList *cmdList; + LIST cmdList; int bIsAutoRTL; WORD wMinute; }; diff --git a/src/mir_core/mc.cpp b/src/mir_core/mc.cpp index 57b91eb367..e440160dc0 100644 --- a/src/mir_core/mc.cpp +++ b/src/mir_core/mc.cpp @@ -74,7 +74,7 @@ MIR_CORE_DLL(void) db_mc_enable(BOOL bEnabled) MIR_CORE_DLL(int) db_mc_isMeta(MCONTACT hContact) { - if (currDb == NULL || !g_bEnabled) return false; + if (currDb == NULL) return false; DBCachedContact *cc = currDb->m_cache->GetCachedContact(hContact); return (cc == NULL) ? false : cc->nSubs != -1; @@ -82,7 +82,7 @@ MIR_CORE_DLL(int) db_mc_isMeta(MCONTACT hContact) MIR_CORE_DLL(int) db_mc_isSub(MCONTACT hContact) { - if (currDb == NULL || !g_bEnabled) return false; + if (currDb == NULL) return false; DBCachedContact *cc = currDb->m_cache->GetCachedContact(hContact); return (cc == NULL) ? false : cc->parentID != 0; @@ -115,7 +115,7 @@ MIR_CORE_DLL(int) db_mc_getSubCount(MCONTACT hMetaContact) // returns parent hContact for a subcontact or INVALID_CONTACT_ID if it's not a sub MIR_CORE_DLL(MCONTACT) db_mc_getMeta(MCONTACT hSubContact) { - if (currDb == NULL || !g_bEnabled) return false; + if (currDb == NULL) return false; DBCachedContact *cc = currDb->m_cache->GetCachedContact(hSubContact); return (cc == NULL) ? NULL : cc->parentID; diff --git a/src/modules/metacontacts/meta_services.cpp b/src/modules/metacontacts/meta_services.cpp index 556b6999f5..89d2c309d2 100644 --- a/src/modules/metacontacts/meta_services.cpp +++ b/src/modules/metacontacts/meta_services.cpp @@ -254,10 +254,9 @@ information about the ACK. * @return 0 on success, 1 otherwise. */ -int Meta_HandleACK(WPARAM wParam, LPARAM lParam) +int Meta_HandleACK(WPARAM, LPARAM lParam) { ACKDATA *ack = (ACKDATA*)lParam; - DBCachedContact *cc = CheckMeta(ack->hContact); if (cc == NULL) return 0; @@ -597,11 +596,13 @@ int Meta_SrmmIconClicked(WPARAM hMeta, LPARAM lParam) int Meta_ClistDoubleClicked(WPARAM hMeta, LPARAM lParam) { - DBCachedContact *cc = currDb->m_cache->GetCachedContact(hMeta); - if (cc != NULL && cc->IsSub()) { - // simulate double click on the metacontact and stop event processing - CallService(MS_CLIST_CONTACTDOUBLECLICKED, cc->parentID, 0); - return 1; + if (db_mc_isEnabled()) { + DBCachedContact *cc = currDb->m_cache->GetCachedContact(hMeta); + if (cc != NULL && cc->IsSub()) { + // simulate double click on the metacontact and stop event processing + CallService(MS_CLIST_CONTACTDOUBLECLICKED, cc->parentID, 0); + return 1; + } } return 0; -- cgit v1.2.3