summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-04-03 16:30:25 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-04-03 16:30:25 +0300
commit9613f96e6a6f96ad02a0fc926054132811ae2bb1 (patch)
treef8fe94a3efe7598a2af926f264d354f7a08fb943 /src
parent2f880bda3aa2d8817ce43481df9d99b12ed82a58 (diff)
Accounts() : iterator for accounts
Diffstat (limited to 'src')
-rw-r--r--src/core/stdautoaway/src/autoaway.cpp7
-rw-r--r--src/core/stdaway/src/sendmsg.cpp19
-rw-r--r--src/core/stdclist/src/clistopts.cpp13
-rw-r--r--src/core/stduseronline/src/useronline.cpp11
-rw-r--r--src/mir_app/src/mir_app.def1
-rw-r--r--src/mir_app/src/mir_app64.def1
-rw-r--r--src/mir_app/src/proto_accs.cpp2
-rw-r--r--src/mir_app/src/proto_opts.cpp1
-rw-r--r--src/mir_app/src/protocols.cpp6
9 files changed, 20 insertions, 41 deletions
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;
}
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index bcfd2f2387..78bd18a0a5 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -534,3 +534,4 @@ Proto_SetUniqueId @549
?IsVisible@PROTOACCOUNT@@QBE_NXZ @554 NONAME
?SetUniqueId@CMPluginBase@@IAEXPBD@Z @555 NONAME
Clist_GetProtocolVisibility @556
+?Accounts@@YGAAU?$LIST@UPROTOACCOUNT@@@@XZ @557 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index a95dca797e..92676a8a6e 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -534,3 +534,4 @@ Proto_SetUniqueId @549
?IsVisible@PROTOACCOUNT@@QEBA_NXZ @554 NONAME
?SetUniqueId@CMPluginBase@@IEAAXPEBD@Z @555 NONAME
Clist_GetProtocolVisibility @556
+?Accounts@@YAAEAU?$LIST@UPROTOACCOUNT@@@@XZ @557 NONAME
diff --git a/src/mir_app/src/proto_accs.cpp b/src/mir_app/src/proto_accs.cpp
index e23ae1296d..109b9e9421 100644
--- a/src/mir_app/src/proto_accs.cpp
+++ b/src/mir_app/src/proto_accs.cpp
@@ -49,7 +49,6 @@ static int EnumDbModules(const char *szModuleName, void*)
if (szProtoName) {
if (!Proto_GetAccount(szModuleName)) {
PROTOACCOUNT *pa = (PROTOACCOUNT*)mir_calloc(sizeof(PROTOACCOUNT));
- pa->cbSize = sizeof(*pa);
pa->szModuleName = mir_strdup(szModuleName);
pa->szProtoName = szProtoName.detach();
pa->tszAccountName = mir_a2u(szModuleName);
@@ -77,7 +76,6 @@ void LoadDbAccounts(void)
PROTOACCOUNT *pa = Proto_GetAccount(szModuleName);
if (pa == nullptr) {
pa = (PROTOACCOUNT*)mir_calloc(sizeof(PROTOACCOUNT));
- pa->cbSize = sizeof(*pa);
pa->szModuleName = szModuleName;
accounts.insert(pa);
}
diff --git a/src/mir_app/src/proto_opts.cpp b/src/mir_app/src/proto_opts.cpp
index 7d6553f804..d2f21b548d 100644
--- a/src/mir_app/src/proto_opts.cpp
+++ b/src/mir_app/src/proto_opts.cpp
@@ -62,7 +62,6 @@ MIR_APP_DLL(PROTOACCOUNT*) Proto_CreateAccount(const char *pszInternal, const ch
return nullptr;
PROTOACCOUNT *pa = (PROTOACCOUNT*)mir_calloc(sizeof(PROTOACCOUNT));
- pa->cbSize = sizeof(PROTOACCOUNT);
pa->bIsEnabled = pa->bIsVisible = true;
pa->iOrder = accounts.getCount();
pa->szProtoName = mir_strdup(pszBaseProto);
diff --git a/src/mir_app/src/protocols.cpp b/src/mir_app/src/protocols.cpp
index 9699129981..53b00388da 100644
--- a/src/mir_app/src/protocols.cpp
+++ b/src/mir_app/src/protocols.cpp
@@ -124,7 +124,6 @@ MIR_APP_DLL(int) Proto_RegisterModule(PROTOCOLDESCRIPTOR *pd)
PROTOACCOUNT *pa = Proto_GetAccount(pd->szName);
if (pa == nullptr) {
pa = (PROTOACCOUNT*)mir_calloc(sizeof(PROTOACCOUNT));
- pa->cbSize = sizeof(PROTOACCOUNT);
pa->szModuleName = mir_strdup(pd->szName);
pa->szProtoName = mir_strdup(pd->szName);
pa->tszAccountName = mir_a2u(pd->szName);
@@ -324,6 +323,11 @@ MIR_APP_DLL(void) Proto_EnumAccounts(int *nAccs, PROTOACCOUNT ***pAccs)
if (pAccs) *pAccs = accounts.getArray();
}
+MIR_APP_DLL(LIST<PROTOACCOUNT>&) Accounts(void)
+{
+ return accounts;
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
bool PROTOACCOUNT::IsEnabled() const