From 609c3041668b36bc6abfa9511aa4e197bf0060ff Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 7 Apr 2018 13:51:06 +0300 Subject: duplicate ME_PROTO_ACK handlers merged together --- plugins/Clist_modern/src/modern_clc.cpp | 15 ++------- plugins/Clist_modern/src/modern_clisttray.cpp | 45 +++++++++++---------------- plugins/Clist_nicer/src/statusbar.cpp | 5 ++- src/mir_app/src/clc.cpp | 17 ++++++++++ src/mir_app/src/clistmod.cpp | 25 --------------- 5 files changed, 40 insertions(+), 67 deletions(-) diff --git a/plugins/Clist_modern/src/modern_clc.cpp b/plugins/Clist_modern/src/modern_clc.cpp index 1230408ffb..371d7ce1f2 100644 --- a/plugins/Clist_modern/src/modern_clc.cpp +++ b/plugins/Clist_modern/src/modern_clc.cpp @@ -1648,19 +1648,8 @@ int ClcUnloadModule() int ClcDoProtoAck(ACKDATA *ack) { if (MirandaExiting()) return 0; - if (ack->type == ACKTYPE_STATUS) { - if (ack->result == ACKRESULT_SUCCESS) { - for (int i = 0; i < pcli->hClcProtoCount; i++) { - if (!mir_strcmp(pcli->clcProto[i].szProto, ack->szModule)) { - pcli->clcProto[i].dwStatus = (WORD)ack->lParam; - if (pcli->clcProto[i].dwStatus >= ID_STATUS_OFFLINE) - Clist_TrayIconUpdateBase(pcli->clcProto[i].szProto); - return 0; - } - } - } - } - else if (ack->type == ACKTYPE_AWAYMSG) { + + if (ack->type == ACKTYPE_AWAYMSG) { if (ack->result == ACKRESULT_SUCCESS && ack->lParam) { if (ack->szModule != nullptr) if (db_get_b(ack->hContact, ack->szModule, "ChatRoom", 0) != 0) diff --git a/plugins/Clist_modern/src/modern_clisttray.cpp b/plugins/Clist_modern/src/modern_clisttray.cpp index 40e25870c9..2e553b55f0 100644 --- a/plugins/Clist_modern/src/modern_clisttray.cpp +++ b/plugins/Clist_modern/src/modern_clisttray.cpp @@ -57,37 +57,33 @@ char* g_szConnectingProto = nullptr; int GetStatusVal(int status) { + if (IsStatusConnecting(status)) // 'connecting' status has the top priority + return 600; + switch (status) { - case ID_STATUS_OFFLINE: return 50; - case ID_STATUS_ONLINE: return 100; - case ID_STATUS_FREECHAT: return 110; - case ID_STATUS_INVISIBLE: return 120; - case ID_STATUS_AWAY: return 200; - case ID_STATUS_DND: return 210; - case ID_STATUS_NA: return 220; - case ID_STATUS_OCCUPIED: return 230; - case ID_STATUS_ONTHEPHONE: return 400; - case ID_STATUS_OUTTOLUNCH: return 410; + case ID_STATUS_OFFLINE: return 50; + case ID_STATUS_ONLINE: return 100; + case ID_STATUS_FREECHAT: return 110; + case ID_STATUS_INVISIBLE: return 120; + case ID_STATUS_AWAY: return 200; + case ID_STATUS_DND: return 210; + case ID_STATUS_NA: return 220; + case ID_STATUS_OCCUPIED: return 230; + case ID_STATUS_ONTHEPHONE: return 400; + case ID_STATUS_OUTTOLUNCH: return 410; } - if (status > 0 && status < ID_STATUS_OFFLINE) - return 600; // 'connecting' status has the top priority return 0; } -int GetStatusOrder(int currentStatus, int newStatus) -{ - int current = GetStatusVal(currentStatus); - int newstat = GetStatusVal(newStatus); - return (current > newstat) ? currentStatus : newStatus; -} - INT_PTR CListTray_GetGlobalStatus(WPARAM, LPARAM) { g_szConnectingProto = nullptr; int curstatus = 0; int connectingCount = 0; + g_bMultiConnectionMode = false; + for (int i = 0; i < pcli->hClcProtoCount; i++) { ClcProtoStatus &p = pcli->clcProto[i]; if (!Clist_GetProtocolVisibility(p.szProto)) @@ -97,16 +93,13 @@ INT_PTR CListTray_GetGlobalStatus(WPARAM, LPARAM) connectingCount++; if (connectingCount == 1) g_szConnectingProto = p.szProto; + else + g_bMultiConnectionMode = true; } - else curstatus = GetStatusOrder(curstatus, p.dwStatus); + else if (GetStatusVal(p.dwStatus) > GetStatusVal(curstatus)) + curstatus = p.dwStatus; } - if (connectingCount == 0) - g_bMultiConnectionMode = FALSE; - else if (connectingCount > 1) - g_bMultiConnectionMode = TRUE; - else - g_bMultiConnectionMode = FALSE; return curstatus ? curstatus : ID_STATUS_OFFLINE; } diff --git a/plugins/Clist_nicer/src/statusbar.cpp b/plugins/Clist_nicer/src/statusbar.cpp index 16ab1a814f..d1e1789c81 100644 --- a/plugins/Clist_nicer/src/statusbar.cpp +++ b/plugins/Clist_nicer/src/statusbar.cpp @@ -87,7 +87,6 @@ LRESULT CALLBACK NewStatusBarWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM HDC hdc = BeginPaint(hwnd, &ps); HDC hdcMem = CreateCompatibleDC(hdc); RECT rcClient, rcWindow; - DRAWITEMSTRUCT dis = { 0 }; BYTE windowStyle = db_get_b(NULL, "CLUI", "WindowStyle", SETTING_WINDOWSTYLE_DEFAULT); LONG b_offset = cfg::dat.bClipBorder + (windowStyle == SETTING_WINDOWSTYLE_NOBORDER ? 2 : (windowStyle == SETTING_WINDOWSTYLE_THINBORDER ? 1 : 0)); @@ -113,9 +112,9 @@ LRESULT CALLBACK NewStatusBarWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM item->CORNER, item->BORDERSTYLE, item->imageItem); SetTextColor(hdcMem, item->TEXTCOLOR); } - else - SetTextColor(hdcMem, GetSysColor(COLOR_BTNTEXT)); + else SetTextColor(hdcMem, GetSysColor(COLOR_BTNTEXT)); + DRAWITEMSTRUCT dis = { 0 }; dis.hwndItem = hwnd; dis.hDC = hdcMem; dis.CtlType = 0; diff --git a/src/mir_app/src/clc.cpp b/src/mir_app/src/clc.cpp index 0cb995c13e..7dd25496ae 100644 --- a/src/mir_app/src/clc.cpp +++ b/src/mir_app/src/clc.cpp @@ -156,11 +156,28 @@ static int ClcProtoAck(WPARAM, LPARAM lParam) { ACKDATA *ack = (ACKDATA *)lParam; if (ack->type == ACKTYPE_STATUS) { + cli.pfnCluiProtocolStatusChanged(lParam, ack->szModule); + + if ((INT_PTR)ack->hProcess < ID_STATUS_ONLINE && ack->lParam >= ID_STATUS_ONLINE) { + // if we're going offline, kill all contacts scheduled for deletion + DWORD caps = (DWORD)CallProtoServiceInt(0, ack->szModule, PS_GETCAPS, PFLAGNUM_1, 0); + if (caps & PF1_SERVERCLIST) { + for (MCONTACT hContact = db_find_first(ack->szModule); hContact; ) { + MCONTACT hNext = db_find_next(hContact, ack->szModule); + if (db_get_b(hContact, "CList", "Delete", 0)) + db_delete_contact(hContact); + hContact = hNext; + } + } + } + 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; + Clist_TrayIconUpdateBase(ack->szModule); break; } } diff --git a/src/mir_app/src/clistmod.cpp b/src/mir_app/src/clistmod.cpp index 683c99e108..04245f11f5 100644 --- a/src/mir_app/src/clistmod.cpp +++ b/src/mir_app/src/clistmod.cpp @@ -109,30 +109,6 @@ MIR_APP_DLL(wchar_t*) Clist_GetStatusModeDescription(int mode, int flags) return (flags & GSMDF_UNTRANSLATED) ? descr : TranslateW(descr); } -static int ProtocolAck(WPARAM, LPARAM lParam) -{ - ACKDATA *ack = (ACKDATA*)lParam; - if (ack->type != ACKTYPE_STATUS) - return 0; - - cli.pfnCluiProtocolStatusChanged(lParam, ack->szModule); - - if ((INT_PTR)ack->hProcess < ID_STATUS_ONLINE && ack->lParam >= ID_STATUS_ONLINE) { - DWORD caps = (DWORD)CallProtoServiceInt(0, ack->szModule, PS_GETCAPS, PFLAGNUM_1, 0); - if (caps & PF1_SERVERCLIST) { - for (MCONTACT hContact = db_find_first(ack->szModule); hContact; ) { - MCONTACT hNext = db_find_next(hContact, ack->szModule); - if (db_get_b(hContact, "CList", "Delete", 0)) - db_delete_contact(hContact); - hContact = hNext; - } - } - } - - Clist_TrayIconUpdateBase(ack->szModule); - return 0; -} - HICON fnGetIconFromStatusMode(MCONTACT hContact, const char *szProto, int status) { return ImageList_GetIcon(hCListImages, cli.pfnIconFromStatusMode(szProto, status, hContact), ILD_NORMAL); @@ -418,7 +394,6 @@ int LoadContactListModule2(void) HookEvent(ME_DB_CONTACT_SETTINGCHANGED, ContactSettingChanged); HookEvent(ME_DB_CONTACT_ADDED, ContactAdded); HookEvent(ME_DB_CONTACT_DELETED, ContactDeleted); - HookEvent(ME_PROTO_ACK, ProtocolAck); hContactDoubleClicked = CreateHookableEvent(ME_CLIST_DOUBLECLICKED); hContactIconChangedEvent = CreateHookableEvent(ME_CLIST_CONTACTICONCHANGED); -- cgit v1.2.3