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 --- src/core/stdautoaway/src/autoaway.cpp | 7 +------ src/core/stdaway/src/sendmsg.cpp | 19 ++++--------------- src/core/stdclist/src/clistopts.cpp | 13 +++++-------- src/core/stduseronline/src/useronline.cpp | 11 +++-------- 4 files changed, 13 insertions(+), 37 deletions(-) (limited to 'src/core') diff --git a/src/core/stdautoaway/src/autoaway.cpp b/src/core/stdautoaway/src/autoaway.cpp index 27531d2b2b..af0a60e441 100644 --- a/src/core/stdautoaway/src/autoaway.cpp +++ b/src/core/stdautoaway/src/autoaway.cpp @@ -57,12 +57,7 @@ static int AutoAwayEvent(WPARAM, LPARAM lParam) if (mii.aaStatus == 0) return 0; - int numAccounts; - PROTOACCOUNT** accounts; - Proto_EnumAccounts(&numAccounts, &accounts); - - for (int i = 0; i < numAccounts; i++) { - PROTOACCOUNT *pa = accounts[i]; + for (auto &pa : Accounts()) { if (!pa->IsEnabled() || pa->IsLocked()) continue; diff --git a/src/core/stdaway/src/sendmsg.cpp b/src/core/stdaway/src/sendmsg.cpp index 52b727f8fe..cbdfe8e782 100644 --- a/src/core/stdaway/src/sendmsg.cpp +++ b/src/core/stdaway/src/sendmsg.cpp @@ -172,12 +172,7 @@ static LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd, UINT msg, WPARAM wPar void ChangeAllProtoMessages(char *szProto, int statusMode, wchar_t *msg) { if (szProto == nullptr) { - int nAccounts; - PROTOACCOUNT **accounts; - Proto_EnumAccounts(&nAccounts, &accounts); - - for (int i = 0; i < nAccounts; i++) { - PROTOACCOUNT *pa = accounts[i]; + for (auto &pa : Accounts()) { if (!pa->IsEnabled()) continue; @@ -536,15 +531,9 @@ static int AwayMsgSendAccountsChanged(WPARAM, LPARAM) { protoModeMsgFlags = 0; - int nAccounts; - PROTOACCOUNT **accounts; - Proto_EnumAccounts(&nAccounts, &accounts); - for (int i = 0; i < nAccounts; i++) { - if (!accounts[i]->IsEnabled()) - continue; - - protoModeMsgFlags |= CallProtoService(accounts[i]->szModuleName, PS_GETCAPS, PFLAGNUM_3, 0); - } + for (auto &pa : Accounts()) + if (pa->IsEnabled()) + protoModeMsgFlags |= CallProtoService(pa->szModuleName, PS_GETCAPS, PFLAGNUM_3, 0); return 0; } diff --git a/src/core/stdclist/src/clistopts.cpp b/src/core/stdclist/src/clistopts.cpp index d17b469d1a..677608a472 100644 --- a/src/core/stdclist/src/clistopts.cpp +++ b/src/core/stdclist/src/clistopts.cpp @@ -103,16 +103,13 @@ static INT_PTR CALLBACK DlgProcGenOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP int item = SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS, CB_ADDSTRING, 0, (LPARAM)TranslateT("Global")); SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS, CB_SETITEMDATA, item, (LPARAM)0); - int count; - PROTOACCOUNT **accs; - Proto_EnumAccounts(&count, &accs); - for (int i = 0; i < count; i++) { - if (!accs[i]->IsEnabled() || CallProtoService(accs[i]->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0) == 0) + for (auto &pa : Accounts()) { + if (!pa->IsEnabled() || CallProtoService(pa->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0) == 0) continue; - item = SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS, CB_ADDSTRING, 0, (LPARAM)accs[i]->tszAccountName); - SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS, CB_SETITEMDATA, item, (LPARAM)accs[i]); - if (!mir_strcmp(szPrimaryStatus, accs[i]->szModuleName)) + item = SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS, CB_ADDSTRING, 0, (LPARAM)pa->tszAccountName); + SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS, CB_SETITEMDATA, item, (LPARAM)pa); + if (!mir_strcmp(szPrimaryStatus, pa->szModuleName)) SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS, CB_SETCURSEL, item, 0); } } diff --git a/src/core/stduseronline/src/useronline.cpp b/src/core/stduseronline/src/useronline.cpp index 2a3c16d49f..ab01edd77a 100644 --- a/src/core/stduseronline/src/useronline.cpp +++ b/src/core/stduseronline/src/useronline.cpp @@ -84,14 +84,9 @@ static int UserOnlineAck(WPARAM, LPARAM lParam) static int UserOnlineModulesLoaded(WPARAM, LPARAM) { - int numAccounts; - PROTOACCOUNT** accounts; - Proto_EnumAccounts(&numAccounts, &accounts); - - // reset the counter - for (int i = 0; i < numAccounts; i++) - if (accounts[i]->IsEnabled()) - db_set_dw(NULL, "UserOnline", accounts[i]->szModuleName, GetTickCount()); + for (auto &pa : Accounts()) + if (pa->IsEnabled()) + db_set_dw(NULL, "UserOnline", pa->szModuleName, GetTickCount()); return 0; } -- cgit v1.2.3