From 9613f96e6a6f96ad02a0fc926054132811ae2bb1 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 3 Apr 2018 16:30:25 +0300 Subject: Accounts() : iterator for accounts --- plugins/NewAwaySysMod/src/AwaySys.cpp | 22 +++++++++------------- plugins/NewAwaySysMod/src/Client.cpp | 21 ++++++--------------- plugins/NewAwaySysMod/src/Properties.h | 11 ++++------- plugins/NewAwaySysMod/src/SetAwayMsg.cpp | 15 +++------------ 4 files changed, 22 insertions(+), 47 deletions(-) (limited to 'plugins/NewAwaySysMod') diff --git a/plugins/NewAwaySysMod/src/AwaySys.cpp b/plugins/NewAwaySysMod/src/AwaySys.cpp index c0d049f1fb..f691316049 100644 --- a/plugins/NewAwaySysMod/src/AwaySys.cpp +++ b/plugins/NewAwaySysMod/src/AwaySys.cpp @@ -229,12 +229,9 @@ int StatusChanged(WPARAM wParam, LPARAM lParam) Flag3 = CallProtoService((char*)lParam, PS_GETCAPS, PFLAGNUM_3, 0); } else { - PROTOACCOUNT **accs; - int numAccs = 0; - Proto_EnumAccounts(&numAccs, &accs); - for (int i = 0; i < numAccs; i++) { - Flag1 |= CallProtoService(accs[i]->szModuleName, PS_GETCAPS, PFLAGNUM_1, 0); - Flag3 |= CallProtoService(accs[i]->szModuleName, PS_GETCAPS, PFLAGNUM_3, 0); + for (auto &pa : Accounts()) { + Flag1 |= CallProtoService(pa->szModuleName, PS_GETCAPS, PFLAGNUM_1, 0); + Flag3 |= CallProtoService(pa->szModuleName, PS_GETCAPS, PFLAGNUM_3, 0); } } @@ -585,14 +582,13 @@ int MirandaLoaded(WPARAM, LPARAM) InitUpdateMsgs(); g_IconList.ReloadIcons(); - int numAccs = 0; - PROTOACCOUNT **accs; - Proto_EnumAccounts(&numAccs, &accs); - for (int i = 0, CurProtoIndex = 0; i < numAccs && CurProtoIndex < MAXICQACCOUNTS; i++) { - HANDLE hHook = HookEvent(CString(accs[i]->szModuleName) + ME_ICQ_STATUSMSGREQ, StatusMsgReqHooks[CurProtoIndex]); + int CurProtoIndex = 0; + for (auto &pa : Accounts()) { + HANDLE hHook = HookEvent(CString(pa->szModuleName) + ME_ICQ_STATUSMSGREQ, StatusMsgReqHooks[CurProtoIndex]); if (hHook) { - ICQProtoList[CurProtoIndex] = accs[i]->szModuleName; - CurProtoIndex++; + ICQProtoList[CurProtoIndex++] = pa->szModuleName; + if (CurProtoIndex >= MAXICQACCOUNTS) + break; } } diff --git a/plugins/NewAwaySysMod/src/Client.cpp b/plugins/NewAwaySysMod/src/Client.cpp index a062efb8ac..ec121bf903 100644 --- a/plugins/NewAwaySysMod/src/Client.cpp +++ b/plugins/NewAwaySysMod/src/Client.cpp @@ -32,14 +32,9 @@ void __cdecl UpdateMsgsThreadProc(void *) { Thread_SetName("NewAwaySysMod: UpdateMsgsThreadProc"); - int numAccs; - PROTOACCOUNT **accs; - Proto_EnumAccounts(&numAccs, &accs); - while (WaitForSingleObject(g_hTerminateUpdateMsgsThread, 0) == WAIT_TIMEOUT && !Miranda_IsTerminated()) { DWORD MinUpdateTimeDifference = (DWORD)g_MoreOptPage.GetDBValueCopy(IDC_MOREOPTDLG_UPDATEMSGSPERIOD) * 1000; // in milliseconds - for (int i = 0; i < numAccs; i++) { - PROTOACCOUNT *p = accs[i]; + for (auto &p : Accounts()) { if (CallProtoService(p->szModuleName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_MODEMSGSEND && !IsAnICQProto(p->szModuleName)) { int Status = CallProtoService(p->szModuleName, PS_GETSTATUS, 0, 0); if (Status < ID_STATUS_OFFLINE || Status > ID_STATUS_OUTTOLUNCH) { @@ -92,17 +87,13 @@ void ChangeProtoMessages(char* szProto, int iMode, const TCString &Msg) g_ProtoStates[szProto].CurStatusMsg = CurMsg; } else { // change message of all protocols - int numAccs; - PROTOACCOUNT **accs; - Proto_EnumAccounts(&numAccs, &accs); - for (int i = 0; i < numAccs; i++) { - PROTOACCOUNT *p = accs[i]; - if (!db_get_b(NULL, p->szModuleName, "LockMainStatus", 0)) { + for (auto &pa : Accounts()) { + if (!db_get_b(NULL, pa->szModuleName, "LockMainStatus", 0)) { if (Msg == nullptr) - CurMsg = GetDynamicStatMsg(INVALID_CONTACT_ID, p->szModuleName); + CurMsg = GetDynamicStatMsg(INVALID_CONTACT_ID, pa->szModuleName); - CallAllowedPS_SETAWAYMSG(p->szModuleName, iMode, CurMsg); - g_ProtoStates[p->szModuleName].CurStatusMsg = CurMsg; + CallAllowedPS_SETAWAYMSG(pa->szModuleName, iMode, CurMsg); + g_ProtoStates[pa->szModuleName].CurStatusMsg = CurMsg; } } } diff --git a/plugins/NewAwaySysMod/src/Properties.h b/plugins/NewAwaySysMod/src/Properties.h index 64180a6405..5c7f42d718 100644 --- a/plugins/NewAwaySysMod/src/Properties.h +++ b/plugins/NewAwaySysMod/src/Properties.h @@ -257,13 +257,10 @@ public: return ProtoStates[i]; // we need to be sure that we have _all_ protocols in the list, before dealing with global status, so we're adding them here. - if (!szProto) { - int numAccs; - PROTOACCOUNT **accs; - Proto_EnumAccounts(&numAccs, &accs); - for (int i = 0; i < numAccs; i++) - (*this)[accs[i]->szModuleName]; // add a protocol if it isn't in the list yet - } + if (!szProto) + for (auto &pa : Accounts()) + (*this)[pa->szModuleName]; // add a protocol if it isn't in the list yet + return ProtoStates[ProtoStates.AddElem(CProtoState(szProto, this))]; } diff --git a/plugins/NewAwaySysMod/src/SetAwayMsg.cpp b/plugins/NewAwaySysMod/src/SetAwayMsg.cpp index d591f306d4..27d11321be 100644 --- a/plugins/NewAwaySysMod/src/SetAwayMsg.cpp +++ b/plugins/NewAwaySysMod/src/SetAwayMsg.cpp @@ -864,11 +864,7 @@ INT_PTR CALLBACK SetAwayMsgDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA HTREEITEM hSelItem; HTREEITEM hItem = hSelItem = CList->AddInfo(TranslateT("** All contacts **"), CLC_ROOT, CLC_ROOT, NULL, Skin_LoadProtoIcon(nullptr, g_ProtoStates[(char*)nullptr].m_status)); - int numAccs; - PROTOACCOUNT **accs; - Proto_EnumAccounts(&numAccs, &accs); - for (int i = 0; i < numAccs; i++) { - PROTOACCOUNT *p = accs[i]; + for (auto &p : Accounts()) // don't forget to change Recent Message Save loop in the UM_SAM_APPLYANDCLOSE if you're changing something here if (CallProtoService(p->szModuleName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_MODEMSGSEND) { PROTOACCOUNT * acc = Proto_GetAccount(p->szModuleName); @@ -876,7 +872,6 @@ INT_PTR CALLBACK SetAwayMsgDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA if (dat->szProtocol && !mir_strcmp(p->szModuleName, dat->szProtocol)) hSelItem = hItem; } - } CList->SetRedraw(false); for (auto &hContact : Contacts()) { @@ -918,18 +913,14 @@ INT_PTR CALLBACK SetAwayMsgDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA MsgTree->Save(); { // save Recent Messages - int numAccs; - PROTOACCOUNT **accs; - Proto_EnumAccounts(&numAccs, &accs); - for (int i = 0; i < numAccs; i++) { - PROTOACCOUNT *p = accs[i]; + for (auto &p : Accounts()) if (CallProtoService(p->szModuleName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_MODEMSGSEND) { TCString Message(CProtoSettings(p->szModuleName).GetMsgFormat(GMF_PERSONAL)); // yes, we don't specify GMF_TEMPORARY here, because we don't need to save it if (Message != nullptr) CProtoSettings(p->szModuleName).SetMsgFormat(SMF_LAST, Message); // if the user set a message for this protocol, save it to the recent messages ChangeProtoMessages(p->szModuleName, g_ProtoStates[p->szModuleName].m_status, TCString(nullptr)); // and actual setting of a status message for the protocol } - } + TCString Message(CProtoSettings().GetMsgFormat(GMF_PERSONAL)); if (Message != nullptr) CProtoSettings().SetMsgFormat(SMF_LAST, Message); // save the global message to the recent messages -- cgit v1.2.3