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/MyDetails/src/data.cpp | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) (limited to 'plugins/MyDetails/src/data.cpp') diff --git a/plugins/MyDetails/src/data.cpp b/plugins/MyDetails/src/data.cpp index fe0dafb388..5f28e074e0 100644 --- a/plugins/MyDetails/src/data.cpp +++ b/plugins/MyDetails/src/data.cpp @@ -25,19 +25,14 @@ ProtocolArray *protocols = nullptr; void InitProtocolData() { - PROTOACCOUNT **protos; - int count; - Proto_EnumAccounts(&count, &protos); + protocols = new ProtocolArray(10); - protocols = new ProtocolArray(count); - - for (int i = 0; i < count; i++) { - PROTOACCOUNT *acc = protos[i]; - if (acc->szModuleName == nullptr || acc->szModuleName[0] == '\0' || acc->bIsVirtual) + for (auto &pa : Accounts()) { + if (pa->szModuleName == nullptr || pa->szModuleName[0] == '\0' || pa->bIsVirtual) continue; // Found a protocol - Protocol *p = new Protocol(acc->szModuleName, acc->tszAccountName); + Protocol *p = new Protocol(pa->szModuleName, pa->tszAccountName); if (p->IsValid()) protocols->Add(p); else @@ -144,21 +139,13 @@ int Protocol::GetStatus() void Protocol::SetStatus(int aStatus) { if (ServiceExists(MS_CS_SETSTATUSEX)) { - // BEGIN From commomstatus.cpp (KeepStatus) - int i, count, pCount; - PROTOACCOUNT **accs; - - pCount = 0; - Proto_EnumAccounts(&count, &accs); - for (i = 0; i < count; i++) { - if (CallProtoService(accs[i]->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0) == 0) - continue; - pCount++; - } - // END From commomstatus.cpp (KeepStatus) - + int pCount = 0; + for (auto &pa : Accounts()) + if (CallProtoService(pa->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0) != 0) + pCount++; + PROTOCOLSETTINGEX **pse = (PROTOCOLSETTINGEX **)mir_calloc(pCount * sizeof(PROTOCOLSETTINGEX *)); - for (i = 0; i < pCount; i++) { + for (int i = 0; i < pCount; i++) { pse[i] = (PROTOCOLSETTINGEX *)mir_calloc(sizeof(PROTOCOLSETTINGEX)); pse[i]->m_szName = ""; } @@ -172,7 +159,7 @@ void Protocol::SetStatus(int aStatus) CallService(MS_CS_SETSTATUSEX, (WPARAM)&pse, 0); - for (i = 0; i < pCount; i++) + for (int i = 0; i < pCount; i++) mir_free(pse[i]); mir_free(pse); } -- cgit v1.2.3