summaryrefslogtreecommitdiff
path: root/plugins/Clist_modern/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 /plugins/Clist_modern/src
parent2f880bda3aa2d8817ce43481df9d99b12ed82a58 (diff)
Accounts() : iterator for accounts
Diffstat (limited to 'plugins/Clist_modern/src')
-rw-r--r--plugins/Clist_modern/src/modern_clcopts.cpp30
-rw-r--r--plugins/Clist_modern/src/modern_clisttray.cpp15
-rw-r--r--plugins/Clist_modern/src/modern_clui.cpp10
-rw-r--r--plugins/Clist_modern/src/modern_contact.cpp13
-rw-r--r--plugins/Clist_modern/src/modern_statusbar.cpp16
-rw-r--r--plugins/Clist_modern/src/modern_statusbar_options.cpp15
-rw-r--r--plugins/Clist_modern/src/modern_viewmodebar.cpp17
7 files changed, 38 insertions, 78 deletions
diff --git a/plugins/Clist_modern/src/modern_clcopts.cpp b/plugins/Clist_modern/src/modern_clcopts.cpp
index 56b9b2ace6..11f08454c7 100644
--- a/plugins/Clist_modern/src/modern_clcopts.cpp
+++ b/plugins/Clist_modern/src/modern_clcopts.cpp
@@ -470,12 +470,9 @@ static INT_PTR CALLBACK DlgProcClistListOpts(HWND hwndDlg, UINT msg, WPARAM wPar
static int _GetNetVisibleProtoCount()
{
- int count, netProtoCount;
- PROTOACCOUNT **accs;
- Proto_EnumAccounts(&count, &accs);
-
- for (int i = 0, netProtoCount = 0; i < count; i++)
- if (accs[i]->IsVisible())
+ int netProtoCount = 0;
+ for (auto &pa : Accounts())
+ if (pa->IsVisible())
netProtoCount++;
return netProtoCount;
@@ -606,22 +603,19 @@ static INT_PTR CALLBACK DlgProcTrayOpts(HWND hwndDlg, UINT msg, WPARAM wParam, L
// == Tray icon mode ==
// preparing account list.
{
- int AccNum, i, siS, siV, item;
- PROTOACCOUNT **acc;
- Proto_EnumAccounts(&AccNum, &acc);
-
- for (siS = siV = -1, i = 0; i < AccNum; i++) {
- if (!acc[i]->bIsVirtual && acc[i]->bIsVisible && !acc[i]->bDynDisabled && acc[i]->bIsEnabled) {
- item = SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS_S, CB_ADDSTRING, 0, (LPARAM)acc[i]->tszAccountName);
- SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS_S, CB_SETITEMDATA, item, (LPARAM)acc[i]);
+ int siS = -1, siV = -1;
+ for (auto &pa : Accounts()) {
+ if (!pa->bIsVirtual && pa->bIsVisible && !pa->bDynDisabled && pa->bIsEnabled) {
+ int item = SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS_S, CB_ADDSTRING, 0, (LPARAM)pa->tszAccountName);
+ SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS_S, CB_SETITEMDATA, item, (LPARAM)pa);
- if (!mir_strcmp(acc[i]->szModuleName, db_get_sa(0, "CList", "tiAccS")))
+ if (!mir_strcmp(pa->szModuleName, db_get_sa(0, "CList", "tiAccS")))
siS = item;
- item = SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS_V, CB_ADDSTRING, 0, (LPARAM)acc[i]->tszAccountName);
- SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS_V, CB_SETITEMDATA, item, (LPARAM)acc[i]);
+ item = SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS_V, CB_ADDSTRING, 0, (LPARAM)pa->tszAccountName);
+ SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS_V, CB_SETITEMDATA, item, (LPARAM)pa);
- if (!mir_strcmp(acc[i]->szModuleName, db_get_sa(0, "CList", "tiAccV")))
+ if (!mir_strcmp(pa->szModuleName, db_get_sa(0, "CList", "tiAccV")))
siV = item;
}
diff --git a/plugins/Clist_modern/src/modern_clisttray.cpp b/plugins/Clist_modern/src/modern_clisttray.cpp
index 49d924a24b..20ae2065a3 100644
--- a/plugins/Clist_modern/src/modern_clisttray.cpp
+++ b/plugins/Clist_modern/src/modern_clisttray.cpp
@@ -274,17 +274,12 @@ void SettingsMigrate(void)
static int GetGoodAccNum(bool *bDiffers, bool *bConn = nullptr)
{
- PROTOACCOUNT **acc;
- int AccNum;
- Proto_EnumAccounts(&AccNum, &acc);
-
*bDiffers = false;
if (bConn)
*bConn = false;
int iPrevStatus = 0, res = 0;
- while (AccNum--) {
- PROTOACCOUNT *pa = acc[AccNum];
+ for (auto &pa : Accounts()) {
if (!pa->IsVisible())
continue;
@@ -373,15 +368,9 @@ int cliTrayIconInit(HWND hwnd)
break;
case TRAY_ICON_MODE_ALL:
- PROTOACCOUNT **acc;
- int AccNum;
- Proto_EnumAccounts(&AccNum, &acc);
-
- for (int i = AccNum; i--;) {
- PROTOACCOUNT *pa = acc[i];
+ for (auto &pa : Accounts().rev_iter())
if (pa->IsVisible() && pa->ppro != nullptr)
pcli->pfnTrayIconAdd(hwnd, pa->szModuleName, nullptr, pa->ppro->m_iStatus);
- }
break;
}
diff --git a/plugins/Clist_modern/src/modern_clui.cpp b/plugins/Clist_modern/src/modern_clui.cpp
index 7763e5c34a..64b47b95d8 100644
--- a/plugins/Clist_modern/src/modern_clui.cpp
+++ b/plugins/Clist_modern/src/modern_clui.cpp
@@ -1053,13 +1053,9 @@ int CLUI_ReloadCLUIOptions()
void CLUI_DisconnectAll()
{
- PROTOACCOUNT **accs;
- int nProtoCount;
- Proto_EnumAccounts(&nProtoCount, &accs);
-
- for (int nProto = 0; nProto < nProtoCount; nProto++)
- if (accs[nProto]->IsEnabled())
- CallProtoService(accs[nProto]->szModuleName, PS_SETSTATUS, ID_STATUS_OFFLINE, 0);
+ for (auto &pa : Accounts())
+ if (pa->IsEnabled())
+ CallProtoService(pa->szModuleName, PS_SETSTATUS, ID_STATUS_OFFLINE, 0);
}
static int CLUI_DrawMenuBackGround(HWND hwnd, HDC hdc, int item, int state)
diff --git a/plugins/Clist_modern/src/modern_contact.cpp b/plugins/Clist_modern/src/modern_contact.cpp
index 3e15378cf1..c56b9622f9 100644
--- a/plugins/Clist_modern/src/modern_contact.cpp
+++ b/plugins/Clist_modern/src/modern_contact.cpp
@@ -76,15 +76,10 @@ DWORD CompareContacts2_getLMTime(MCONTACT hContact)
int GetProtoIndex(char * szName)
{
- if (szName) {
- PROTOACCOUNT **accs = nullptr;
- int accCount = 0;
- Proto_EnumAccounts(&accCount, &accs);
-
- for (int i = 0; i < accCount; i++)
- if (!mir_strcmpi(szName, accs[i]->szModuleName))
- return accs[i]->iOrder;
- }
+ if (szName)
+ for (auto &pa : Accounts())
+ if (!mir_strcmpi(szName, pa->szModuleName))
+ return pa->iOrder;
return -1;
}
diff --git a/plugins/Clist_modern/src/modern_statusbar.cpp b/plugins/Clist_modern/src/modern_statusbar.cpp
index ccb7808d7b..1b396c6652 100644
--- a/plugins/Clist_modern/src/modern_statusbar.cpp
+++ b/plugins/Clist_modern/src/modern_statusbar.cpp
@@ -167,14 +167,12 @@ int ModernDrawStatusBarWorker(HWND hWnd, HDC hDC)
ProtosData.destroy();
- int protoCount;
- PROTOACCOUNT **accs;
- Proto_EnumAccounts(&protoCount, &accs);
- if (protoCount == 0)
+ auto &accs = Accounts();
+ if (accs.getCount() == 0)
return 0;
int iProtoInStatusMenu = 0;
- for (int j = 0; j < protoCount; j++) {
+ for (int j = 0; j < accs.getCount(); j++) {
int i = pcli->pfnGetAccountIndexByPos(j);
if (i == -1)
continue;
@@ -266,7 +264,6 @@ int ModernDrawStatusBarWorker(HWND hWnd, HDC hDC)
return 0;
// START MULTILINE HERE
- int orig_protoCount = protoCount;
int orig_visProtoCount = ProtosData.getCount();
int protosperline = 0;
@@ -274,9 +271,9 @@ int ModernDrawStatusBarWorker(HWND hWnd, HDC hDC)
protosperline = g_StatusBarData.nProtosPerLine;
else if (orig_visProtoCount)
protosperline = orig_visProtoCount;
- else if (protoCount) {
- protosperline = protoCount;
- orig_visProtoCount = protoCount;
+ else if (accs.getCount()) {
+ protosperline = accs.getCount();
+ orig_visProtoCount = accs.getCount();
}
else {
protosperline = 1;
@@ -287,7 +284,6 @@ int ModernDrawStatusBarWorker(HWND hWnd, HDC hDC)
int linecount = protosperline ? (orig_visProtoCount + (protosperline - 1)) / protosperline : 1; // divide with rounding to up
for (int line = 0; line < linecount; line++) {
int rowheight = 2 + max(textSize.cy, iconHeight);
- protoCount = min(protosperline, (orig_protoCount - line*protosperline));
int visProtoCount = min(protosperline, (orig_visProtoCount - line*protosperline));
GetClientRect(hWnd, &rc);
diff --git a/plugins/Clist_modern/src/modern_statusbar_options.cpp b/plugins/Clist_modern/src/modern_statusbar_options.cpp
index 69bd3e30d2..6a56cd1270 100644
--- a/plugins/Clist_modern/src/modern_statusbar_options.cpp
+++ b/plugins/Clist_modern/src/modern_statusbar_options.cpp
@@ -158,22 +158,18 @@ INT_PTR CALLBACK DlgProcSBarOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
// populate per-proto list box.
SendMessage(hwndComboBox, CB_RESETCONTENT, 0, 0);
- int count;
- PROTOACCOUNT **accs;
- Proto_EnumAccounts(&count, &accs);
-
SendMessage(hwndComboBox, CB_ADDSTRING, 0, (LPARAM)TranslateT("<<Global>>"));
SendMessage(hwndComboBox, CB_SETITEMDATA, 0, 0);
- for (int i = 0; i < count; i++) {
- if (accs[i]->bIsVirtual)
+ for (auto &pa : Accounts()) {
+ if (pa->bIsVirtual)
continue;
- char *szName = accs[i]->szModuleName;
+ char *szName = pa->szModuleName;
dat = (StatusBarProtocolOptions *)mir_calloc(sizeof(StatusBarProtocolOptions));
dat->szName = szName;
- DWORD dwNewId = SendMessage(hwndComboBox, CB_ADDSTRING, 0, (LPARAM)accs[i]->tszAccountName);
+ DWORD dwNewId = SendMessage(hwndComboBox, CB_ADDSTRING, 0, (LPARAM)pa->tszAccountName);
SendMessage(hwndComboBox, CB_SETITEMDATA, dwNewId, (LPARAM)dat);
char buf[256];
@@ -205,8 +201,7 @@ INT_PTR CALLBACK DlgProcSBarOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
dat->PaddingRight = db_get_dw(0, "CLUI", buf, SETTING_PADDINGRIGHT_DEFAULT);
}
- if (count)
- SendMessage(hwndComboBox, CB_SETCURSEL, 0, 0);
+ SendMessage(hwndComboBox, CB_SETCURSEL, 0, 0);
}
_GlobalOptions.AccountIsCustomized = TRUE;
diff --git a/plugins/Clist_modern/src/modern_viewmodebar.cpp b/plugins/Clist_modern/src/modern_viewmodebar.cpp
index 565d2edaeb..f51c72b5ed 100644
--- a/plugins/Clist_modern/src/modern_viewmodebar.cpp
+++ b/plugins/Clist_modern/src/modern_viewmodebar.cpp
@@ -208,17 +208,12 @@ static int FillDialog(HWND hwnd)
ListView_InsertColumn(GetDlgItem(hwnd, IDC_PROTOCOLS), 0, &lvc);
// fill protocols...
- int protoCount;
- PROTOACCOUNT **accs;
- Proto_EnumAccounts(&protoCount, &accs);
- {
- LVITEMA item = { 0 };
- item.mask = LVIF_TEXT;
- item.iItem = 1000;
- for (int i = 0; i < protoCount; i++) {
- item.pszText = accs[i]->szModuleName;
- SendMessageA(hwndList, LVM_INSERTITEMA, 0, (LPARAM)&item);
- }
+ LVITEMA item = { 0 };
+ item.mask = LVIF_TEXT;
+ item.iItem = 1000;
+ for (auto &pa : Accounts()) {
+ item.pszText = pa->szModuleName;
+ SendMessageA(hwndList, LVM_INSERTITEMA, 0, (LPARAM)&item);
}
ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE);