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 --- 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 ++- 5 files changed, 52 insertions(+), 112 deletions(-) (limited to 'src/core/stdmsg') 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; }; -- cgit v1.2.3