From 2c89ab98b84a92c0386700d6911be46ad18edc50 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 7 Apr 2018 14:32:51 +0300 Subject: finally that perversion with double protocol caching in clist died --- include/delphi/m_clistint.inc | 2 -- include/m_clistint.h | 10 +-------- plugins/Clist_modern/src/modern_clisttray.cpp | 13 ++++++------ src/mir_app/src/clc.cpp | 30 +++------------------------ src/mir_app/src/clcidents.cpp | 19 ++++++++--------- src/mir_app/src/menu_clist.cpp | 9 ++++---- 6 files changed, 23 insertions(+), 60 deletions(-) diff --git a/include/delphi/m_clistint.inc b/include/delphi/m_clistint.inc index ea5c91dcbc..724ad30bf7 100644 --- a/include/delphi/m_clistint.inc +++ b/include/delphi/m_clistint.inc @@ -292,8 +292,6 @@ type hwndStatus : HWND; hMenuMain : HMENU; hInst : HMODULE; - hClcProtoCount : int; - clcProto : PClcProtoStatus; (* clc.h *) pfnContactListControlWndProc : function(hwnd:HWND; msg:uint; wParam:WPARAM; lParam:LPARAM):LRESULT; stdcall; diff --git a/include/m_clistint.h b/include/m_clistint.h index d0aeabd3d9..594fa70546 100644 --- a/include/m_clistint.h +++ b/include/m_clistint.h @@ -192,6 +192,7 @@ struct MenuProto ptrA szProto; HGENMENU pMenu; HICON hIcon; + int iStatus; }; ///////////////////////////////////////////////////////////////////////////////////////// @@ -295,12 +296,6 @@ EXTERN_C MIR_APP_DLL(int) Clist_GetAccountIndex(int iPos); ///////////////////////////////////////////////////////////////////////////////////////// // CLIST_INTERFACE structure definition -struct ClcProtoStatus -{ - char *szProto; - DWORD dwStatus; -}; - struct ClcCacheEntryBase { MCONTACT hContact; @@ -316,9 +311,6 @@ struct CLIST_INTERFACE HMENU hMenuMain; HMODULE hInst; - int hClcProtoCount; - ClcProtoStatus *clcProto; - // clc.h LRESULT (CALLBACK *pfnContactListControlWndProc)(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); diff --git a/plugins/Clist_modern/src/modern_clisttray.cpp b/plugins/Clist_modern/src/modern_clisttray.cpp index 2e553b55f0..852998e235 100644 --- a/plugins/Clist_modern/src/modern_clisttray.cpp +++ b/plugins/Clist_modern/src/modern_clisttray.cpp @@ -84,20 +84,19 @@ INT_PTR CListTray_GetGlobalStatus(WPARAM, LPARAM) int connectingCount = 0; g_bMultiConnectionMode = false; - for (int i = 0; i < pcli->hClcProtoCount; i++) { - ClcProtoStatus &p = pcli->clcProto[i]; - if (!Clist_GetProtocolVisibility(p.szProto)) + for (auto &it : *pcli->menuProtos) { + if (!Clist_GetProtocolVisibility(it->szProto)) continue; - if (IsStatusConnecting(p.dwStatus)) { + if (IsStatusConnecting(it->iStatus)) { connectingCount++; if (connectingCount == 1) - g_szConnectingProto = p.szProto; + g_szConnectingProto = it->szProto; else g_bMultiConnectionMode = true; } - else if (GetStatusVal(p.dwStatus) > GetStatusVal(curstatus)) - curstatus = p.dwStatus; + else if (GetStatusVal(it->iStatus) > GetStatusVal(curstatus)) + curstatus = it->iStatus; } return curstatus ? curstatus : ID_STATUS_OFFLINE; diff --git a/src/mir_app/src/clc.cpp b/src/mir_app/src/clc.cpp index 7dd25496ae..8c0014d50d 100644 --- a/src/mir_app/src/clc.cpp +++ b/src/mir_app/src/clc.cpp @@ -124,30 +124,8 @@ static int ClcSettingChanged(WPARAM hContact, LPARAM lParam) return 0; } -static int ClcAccountsChanged(WPARAM, LPARAM) -{ - int cnt = 0; - for (auto &pa : accounts) - if (pa->IsEnabled()) - cnt++; - - cli.hClcProtoCount = cnt; - cli.clcProto = (ClcProtoStatus *)mir_realloc(cli.clcProto, sizeof(ClcProtoStatus) * cli.hClcProtoCount); - - cnt = 0; - for (auto &pa : accounts) { - if (pa->IsEnabled()) { - cli.clcProto[cnt].szProto = pa->szModuleName; - cli.clcProto[cnt].dwStatus = CallProtoServiceInt(0, pa->szModuleName, PS_GETSTATUS, 0, 0); - ++cnt; - } - } - return 0; -} - static int ClcModulesLoaded(WPARAM, LPARAM) { - ClcAccountsChanged(0, 0); MTG_OnmodulesLoad(); return 0; } @@ -174,9 +152,9 @@ static int ClcProtoAck(WPARAM, LPARAM lParam) WindowList_BroadcastAsync(hClcWindowList, INTM_INVALIDATE, 0, 0); if (ack->result == ACKRESULT_SUCCESS) { - for (int i = 0; i < cli.hClcProtoCount; i++) { - if (!mir_strcmp(cli.clcProto[i].szProto, ack->szModule)) { - cli.clcProto[i].dwStatus = (WORD)ack->lParam; + for (auto &it : g_menuProtos) { + if (!mir_strcmp(it->szProto, ack->szModule)) { + it->iStatus = (WORD)ack->lParam; Clist_TrayIconUpdateBase(ack->szModule); break; } @@ -229,7 +207,6 @@ int LoadCLCModule(void) CreateServiceFunction(MS_CLC_GETINFOTIPHOVERTIME, GetInfoTipHoverTime); HookEvent(ME_SYSTEM_MODULESLOADED, ClcModulesLoaded); - HookEvent(ME_PROTO_ACCLISTCHANGED, ClcAccountsChanged); HookEvent(ME_DB_CONTACT_SETTINGCHANGED, ClcSettingChanged); HookEvent(ME_DB_CONTACT_ADDED, ClcContactAdded); HookEvent(ME_SKIN_ICONSCHANGED, ClcIconsChanged); @@ -244,7 +221,6 @@ void UnloadClcModule() if (!bModuleInitialized) return; - mir_free(cli.clcProto); WindowList_Destroy(hClcWindowList); hClcWindowList = nullptr; FreeDisplayNameCache(); diff --git a/src/mir_app/src/clcidents.cpp b/src/mir_app/src/clcidents.cpp index e06eba4d51..fbd5e8d245 100644 --- a/src/mir_app/src/clcidents.cpp +++ b/src/mir_app/src/clcidents.cpp @@ -223,9 +223,9 @@ MIR_APP_DLL(int) Clist_GetRealStatus(ClcContact *cc, int iDefaultValue) { char *szProto = cc->proto; if (szProto != nullptr) - for (int i = 0; i < cli.hClcProtoCount; i++) - if (!mir_strcmp(cli.clcProto[i].szProto, szProto)) - return cli.clcProto[i].dwStatus; + for (auto &it : g_menuProtos) + if (!mir_strcmp(it->szProto, szProto)) + return it->iStatus; return iDefaultValue; } @@ -237,13 +237,12 @@ MIR_APP_DLL(int) Clist_GetGeneralizedStatus(char **szProto) int status = ID_STATUS_OFFLINE; int statusOnlineness = 0; - for (int i = 0; i < cli.hClcProtoCount; i++) { - int thisStatus = cli.clcProto[i].dwStatus; - if (thisStatus == ID_STATUS_INVISIBLE) + for (auto &it : g_menuProtos) { + if (it->iStatus == ID_STATUS_INVISIBLE) return ID_STATUS_INVISIBLE; int iStatusWeight; - switch (thisStatus) { + switch (it->iStatus) { case ID_STATUS_FREECHAT: iStatusWeight = 110; break; case ID_STATUS_ONLINE: iStatusWeight = 100; break; case ID_STATUS_OCCUPIED: iStatusWeight = 60; break; @@ -254,14 +253,14 @@ MIR_APP_DLL(int) Clist_GetGeneralizedStatus(char **szProto) case ID_STATUS_NA: iStatusWeight = 10; break; case ID_STATUS_INVISIBLE: iStatusWeight = 5; break; default: - iStatusWeight = IsStatusConnecting(thisStatus) ? 120 : 0; + iStatusWeight = IsStatusConnecting(it->iStatus) ? 120 : 0; break; } if (iStatusWeight > statusOnlineness) { if (szProto != nullptr) - *szProto = cli.clcProto[i].szProto; - status = thisStatus; + *szProto = it->szProto; + status = it->iStatus; statusOnlineness = iStatusWeight; } } diff --git a/src/mir_app/src/menu_clist.cpp b/src/mir_app/src/menu_clist.cpp index c3dd5a83e8..a44c800dc2 100644 --- a/src/mir_app/src/menu_clist.cpp +++ b/src/mir_app/src/menu_clist.cpp @@ -713,8 +713,6 @@ MIR_APP_DLL(int) Clist_GetAccountIndex(int Pos) void RebuildMenuOrder(void) { - BYTE bHideStatusMenu = db_get_b(0, "CLUI", "DontHideStatusMenu", 0); // cool perversion, though - // clear statusmenu RecursiveDeleteMenu(hStatusMenu); @@ -742,13 +740,13 @@ void RebuildMenuOrder(void) continue; PROTOACCOUNT *pa = accounts[i]; - int pos = 0; - if (!bHideStatusMenu && !pa->IsVisible()) + if (!pa->IsVisible()) continue; DWORD flags = pa->ppro->GetCaps(PFLAGNUM_2, 0) & ~pa->ppro->GetCaps(PFLAGNUM_5, 0); HICON ic; wchar_t tbuf[256]; + int pos = 0; // adding root CMenuItem mi; @@ -794,6 +792,7 @@ void RebuildMenuOrder(void) pMenu->hIcon = nullptr; pMenu->pMenu = rootmenu; pMenu->szProto = mir_strdup(pa->szModuleName); + pMenu->iStatus = CallProtoService(pa->szModuleName, PS_GETSTATUS, 0, 0); g_menuProtos.insert(pMenu); char buf[256]; @@ -841,7 +840,7 @@ void RebuildMenuOrder(void) // add to root menu for (int j = 0; j < _countof(statusModeList); j++) { for (auto &pa : accounts) { - if (!bHideStatusMenu && !pa->IsVisible()) + if (!pa->IsVisible()) continue; DWORD flags = pa->ppro->GetCaps(PFLAGNUM_2, 0) & ~pa->ppro->GetCaps(PFLAGNUM_5, 0); -- cgit v1.2.3