diff options
author | George Hazan <ghazan@miranda.im> | 2018-02-21 18:35:04 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-02-21 18:40:14 +0300 |
commit | 5b6db3290cb9c9817cba126bd7aea798a610c31d (patch) | |
tree | f5b51474c51988ac60c20d33d3d6837070e055ce | |
parent | e4e088d37070bab69b1457621706d65472874243 (diff) |
SM: C++'11 iterators
-rw-r--r-- | plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp | 11 | ||||
-rw-r--r-- | plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp | 137 | ||||
-rw-r--r-- | plugins/StatusManager/src/KeepStatus/keepstatus.cpp | 163 | ||||
-rw-r--r-- | plugins/StatusManager/src/StartupStatus/ss_options.cpp | 27 | ||||
-rw-r--r-- | plugins/StatusManager/src/StartupStatus/ss_profiles.cpp | 13 | ||||
-rw-r--r-- | plugins/StatusManager/src/StartupStatus/startupstatus.cpp | 30 | ||||
-rw-r--r-- | plugins/StatusManager/src/commonstatus.cpp | 12 | ||||
-rw-r--r-- | plugins/StatusManager/src/confirmdialog.cpp | 36 | ||||
-rw-r--r-- | plugins/StatusManager/src/main.cpp | 6 |
9 files changed, 205 insertions, 230 deletions
diff --git a/plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp b/plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp index db1fc2fea2..5e3f18e92c 100644 --- a/plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp +++ b/plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp @@ -140,10 +140,9 @@ static INT_PTR CALLBACK DlgProcAutoAwayRulesOpts(HWND hwndDlg, UINT msg, WPARAM // fill list from currentProtoSettings { - for (int i = 0; i < optionSettings.getCount(); i++) { - SMProto &p = optionSettings[i]; - int item = SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, CB_ADDSTRING, 0, (LPARAM)p.m_tszAccName); - SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, CB_SETITEMDATA, item, (LPARAM)&p); + for (auto &p : optionSettings) { + int item = SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, CB_ADDSTRING, 0, (LPARAM)p->m_tszAccName); + SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, CB_SETITEMDATA, item, (LPARAM)p); } } // set cursor to first protocol @@ -334,8 +333,8 @@ static INT_PTR CALLBACK DlgProcAutoAwayRulesOpts(HWND hwndDlg, UINT msg, WPARAM if (bSettingSame) WriteAutoAwaySetting(*sameSetting, SETTING_ALL); else { - for (int i = 0; i < optionSettings.getCount(); i++) - WriteAutoAwaySetting(optionSettings[i], optionSettings[i].m_szName); + for (auto &it : optionSettings) + WriteAutoAwaySetting(*it, it->m_szName); } AAALoadOptions(); } diff --git a/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp b/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp index 6e63df6d32..3f638f22db 100644 --- a/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp +++ b/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp @@ -91,15 +91,15 @@ void AAALoadOptions() monitorKeyboard = db_get_b(0, AAAMODULENAME, SETTING_MONITORKEYBOARD, TRUE); lastInput = lastMirandaInput = GetTickCount(); - for (int i = 0; i < protoList.getCount(); i++) { + for (auto &it : protoList) { char* protoName; if ((db_get_b(0, AAAMODULENAME, SETTING_SAMESETTINGS, 0))) protoName = SETTING_ALL; else - protoName = protoList[i].m_szName; - LoadAutoAwaySetting(protoList[i], protoName); + protoName = it->m_szName; + LoadAutoAwaySetting(*it, protoName); - if (protoList[i].optionFlags & FLAG_MONITORMIRANDA) + if (it->optionFlags & FLAG_MONITORMIRANDA) monitorMiranda = TRUE; else if (ignoreLockKeys || ignoreSysKeys || ignoreAltCombo || (monitorMouse != monitorKeyboard)) monitorAll = TRUE; @@ -207,13 +207,12 @@ static VOID CALLBACK AutoAwayTimer(HWND, UINT, UINT_PTR, DWORD) int statusChanged = FALSE; int confirm = FALSE; - for (int i = 0; i < protoList.getCount(); i++) { - SMProto& aas = protoList[i]; - aas.m_status = ID_STATUS_DISABLED; + for (auto &it : protoList) { + it->m_status = ID_STATUS_DISABLED; BOOL bTrigger = false; - if (aas.optionFlags & FLAG_MONITORMIRANDA) + if (it->optionFlags & FLAG_MONITORMIRANDA) mouseStationaryTimer = (GetTickCount() - lastMirandaInput) / 1000; else { LASTINPUTINFO ii = { sizeof(ii) }; @@ -221,108 +220,108 @@ static VOID CALLBACK AutoAwayTimer(HWND, UINT, UINT_PTR, DWORD) mouseStationaryTimer = (GetTickCount() - ii.dwTime) / 1000; } - int sts1Time = aas.awayTime * SECS_PER_MINUTE; - int sts2Time = aas.naTime * SECS_PER_MINUTE; - int sts1setTime = aas.sts1setTimer == 0 ? 0 : (GetTickCount() - aas.sts1setTimer) / 1000; - int currentMode = CallProtoService(aas.m_szName, PS_GETSTATUS, 0, 0); + int sts1Time = it->awayTime * SECS_PER_MINUTE; + int sts2Time = it->naTime * SECS_PER_MINUTE; + int sts1setTime = it->sts1setTimer == 0 ? 0 : (GetTickCount() - it->sts1setTimer) / 1000; + int currentMode = CallProtoService(it->m_szName, PS_GETSTATUS, 0, 0); - if (aas.optionFlags & FLAG_ONSAVER) + if (it->optionFlags & FLAG_ONSAVER) bTrigger |= IsScreenSaverRunning(); - if (aas.optionFlags & FLAG_ONLOCK) + if (it->optionFlags & FLAG_ONLOCK) bTrigger |= IsWorkstationLocked(); - if (aas.optionFlags & FLAG_FULLSCREEN) + if (it->optionFlags & FLAG_FULLSCREEN) bTrigger |= IsFullScreen(); /* check states */ - if (aas.curState == ACTIVE) { - if (((mouseStationaryTimer >= sts1Time && (aas.optionFlags & FLAG_ONMOUSE)) || bTrigger) && currentMode != aas.lv1Status && aas.statusFlags&StatusModeToProtoFlag(currentMode)) { + if (it->curState == ACTIVE) { + if (((mouseStationaryTimer >= sts1Time && (it->optionFlags & FLAG_ONMOUSE)) || bTrigger) && currentMode != it->lv1Status && it->statusFlags&StatusModeToProtoFlag(currentMode)) { /* from ACTIVE to STATUS1_SET */ - aas.m_lastStatus = aas.originalStatusMode = CallProtoService(aas.m_szName, PS_GETSTATUS, 0, 0); - aas.m_status = aas.lv1Status; - aas.sts1setTimer = GetTickCount(); + it->m_lastStatus = it->originalStatusMode = CallProtoService(it->m_szName, PS_GETSTATUS, 0, 0); + it->m_status = it->lv1Status; + it->sts1setTimer = GetTickCount(); sts1setTime = 0; - aas.statusChanged = statusChanged = TRUE; - changeState(aas, STATUS1_SET); + it->statusChanged = statusChanged = TRUE; + changeState(*it, STATUS1_SET); } - else if (mouseStationaryTimer >= sts2Time && currentMode == aas.lv1Status && currentMode != aas.lv2Status && (aas.optionFlags & FLAG_SETNA) && (aas.statusFlags & StatusModeToProtoFlag(currentMode))) { + else if (mouseStationaryTimer >= sts2Time && currentMode == it->lv1Status && currentMode != it->lv2Status && (it->optionFlags & FLAG_SETNA) && (it->statusFlags & StatusModeToProtoFlag(currentMode))) { /* from ACTIVE to STATUS2_SET */ - aas.m_lastStatus = aas.originalStatusMode = CallProtoService(aas.m_szName, PS_GETSTATUS, 0, 0); - aas.m_status = aas.lv2Status; - aas.statusChanged = statusChanged = TRUE; - changeState(aas, STATUS2_SET); + it->m_lastStatus = it->originalStatusMode = CallProtoService(it->m_szName, PS_GETSTATUS, 0, 0); + it->m_status = it->lv2Status; + it->statusChanged = statusChanged = TRUE; + changeState(*it, STATUS2_SET); } } - if (aas.curState == STATUS1_SET) { - if ((mouseStationaryTimer < sts1Time && !bTrigger) && !(aas.optionFlags & FLAG_RESET)) { + if (it->curState == STATUS1_SET) { + if ((mouseStationaryTimer < sts1Time && !bTrigger) && !(it->optionFlags & FLAG_RESET)) { /* from STATUS1_SET to HIDDEN_ACTIVE */ - changeState(aas, HIDDEN_ACTIVE); - aas.m_lastStatus = CallProtoService(aas.m_szName, PS_GETSTATUS, 0, 0); + changeState(*it, HIDDEN_ACTIVE); + it->m_lastStatus = CallProtoService(it->m_szName, PS_GETSTATUS, 0, 0); } else if (((mouseStationaryTimer < sts1Time) && !bTrigger) && - ((aas.optionFlags & FLAG_LV2ONINACTIVE) || (!(aas.optionFlags&FLAG_SETNA))) && - (aas.optionFlags & FLAG_RESET)) { + ((it->optionFlags & FLAG_LV2ONINACTIVE) || (!(it->optionFlags&FLAG_SETNA))) && + (it->optionFlags & FLAG_RESET)) { /* from STATUS1_SET to SET_ORGSTATUS */ - changeState(aas, SET_ORGSTATUS); + changeState(*it, SET_ORGSTATUS); } - else if ((aas.optionFlags & FLAG_SETNA) && sts1setTime >= sts2Time) { + else if ((it->optionFlags & FLAG_SETNA) && sts1setTime >= sts2Time) { /* when set STATUS2, currentMode doesn't have to be in the selected status list (statusFlags) */ /* from STATUS1_SET to STATUS2_SET */ - aas.m_lastStatus = CallProtoService(aas.m_szName, PS_GETSTATUS, 0, 0); - aas.m_status = aas.lv2Status; - aas.statusChanged = statusChanged = TRUE; - changeState(aas, STATUS2_SET); + it->m_lastStatus = CallProtoService(it->m_szName, PS_GETSTATUS, 0, 0); + it->m_status = it->lv2Status; + it->statusChanged = statusChanged = TRUE; + changeState(*it, STATUS2_SET); } } - if (aas.curState == STATUS2_SET) { - if (mouseStationaryTimer < sts2Time && !bTrigger && (aas.optionFlags & FLAG_RESET)) { + if (it->curState == STATUS2_SET) { + if (mouseStationaryTimer < sts2Time && !bTrigger && (it->optionFlags & FLAG_RESET)) { /* from STATUS2_SET to SET_ORGSTATUS */ - changeState(aas, SET_ORGSTATUS); + changeState(*it, SET_ORGSTATUS); } - else if (mouseStationaryTimer < sts2Time && !bTrigger && !(aas.optionFlags & FLAG_RESET)) { + else if (mouseStationaryTimer < sts2Time && !bTrigger && !(it->optionFlags & FLAG_RESET)) { /* from STATUS2_SET to HIDDEN_ACTIVE */ /* Remember: after status1 is set, and "only on inactive" is NOT set, it implies !reset. */ - changeState(aas, HIDDEN_ACTIVE); - aas.m_lastStatus = CallProtoService(aas.m_szName, PS_GETSTATUS, 0, 0); + changeState(*it, HIDDEN_ACTIVE); + it->m_lastStatus = CallProtoService(it->m_szName, PS_GETSTATUS, 0, 0); } } - if (aas.curState == HIDDEN_ACTIVE) { - if (aas.mStatus) { + if (it->curState == HIDDEN_ACTIVE) { + if (it->mStatus) { /* HIDDEN_ACTIVE to ACTIVE */ - //aas.statusChanged = FALSE; - changeState(aas, ACTIVE); - aas.sts1setTimer = 0; - aas.mStatus = FALSE; + //it->statusChanged = FALSE; + changeState(*it, ACTIVE); + it->sts1setTimer = 0; + it->mStatus = FALSE; } - else if ((aas.optionFlags & FLAG_SETNA) && currentMode == aas.lv1Status && - currentMode != aas.lv2Status && (aas.statusFlags & StatusModeToProtoFlag(currentMode)) && - (mouseStationaryTimer >= sts2Time || (sts1setTime >= sts2Time && !(aas.optionFlags & FLAG_LV2ONINACTIVE)))) { + else if ((it->optionFlags & FLAG_SETNA) && currentMode == it->lv1Status && + currentMode != it->lv2Status && (it->statusFlags & StatusModeToProtoFlag(currentMode)) && + (mouseStationaryTimer >= sts2Time || (sts1setTime >= sts2Time && !(it->optionFlags & FLAG_LV2ONINACTIVE)))) { /* HIDDEN_ACTIVE to STATUS2_SET */ - aas.m_lastStatus = aas.originalStatusMode = CallProtoService(aas.m_szName, PS_GETSTATUS, 0, 0); - aas.m_status = aas.lv2Status; - aas.statusChanged = statusChanged = TRUE; - changeState(aas, STATUS2_SET); + it->m_lastStatus = it->originalStatusMode = CallProtoService(it->m_szName, PS_GETSTATUS, 0, 0); + it->m_status = it->lv2Status; + it->statusChanged = statusChanged = TRUE; + changeState(*it, STATUS2_SET); } } - if (aas.curState == SET_ORGSTATUS) { + if (it->curState == SET_ORGSTATUS) { /* SET_ORGSTATUS to ACTIVE */ - aas.m_lastStatus = CallProtoService(aas.m_szName, PS_GETSTATUS, 0, 0); - aas.m_status = aas.originalStatusMode; - confirm = (aas.optionFlags & FLAG_CONFIRM) ? TRUE : confirm; - aas.statusChanged = statusChanged = TRUE; - changeState(aas, ACTIVE); - aas.sts1setTimer = 0; + it->m_lastStatus = CallProtoService(it->m_szName, PS_GETSTATUS, 0, 0); + it->m_status = it->originalStatusMode; + confirm = (it->optionFlags & FLAG_CONFIRM) ? TRUE : confirm; + it->statusChanged = statusChanged = TRUE; + changeState(*it, ACTIVE); + it->sts1setTimer = 0; } - protoList[i].mStatus = FALSE; + it->mStatus = FALSE; } if (confirm || statusChanged) { TProtoSettings ps = protoList; - for (int i = 0; i < ps.getCount(); i++) - if (ps[i].m_status == ID_STATUS_DISABLED) - ps[i].m_szName = ""; + for (auto &it : ps) + if (it->m_status == ID_STATUS_DISABLED) + it->m_szName = ""; if (confirm) confirmDialog = ShowConfirmDialogEx(&ps, db_get_w(0, AAAMODULENAME, SETTING_CONFIRMDELAY, 5)); diff --git a/plugins/StatusManager/src/KeepStatus/keepstatus.cpp b/plugins/StatusManager/src/KeepStatus/keepstatus.cpp index 31e95c3d0b..42e715a262 100644 --- a/plugins/StatusManager/src/KeepStatus/keepstatus.cpp +++ b/plugins/StatusManager/src/KeepStatus/keepstatus.cpp @@ -131,9 +131,9 @@ static PROTOCOLSETTINGEX** GetCurrentProtoSettingsCopy() { mir_cslock lck(GenStatusCS); PROTOCOLSETTINGEX **ps = (PROTOCOLSETTINGEX**)mir_alloc(protoList.getCount() * sizeof(PROTOCOLSETTINGEX *)); - if (ps == nullptr) { + if (ps == nullptr) return nullptr; - } + for (int i = 0; i < protoList.getCount(); i++) { ps[i] = (PROTOCOLSETTINGEX*)mir_calloc(sizeof(PROTOCOLSETTINGEX)); if (ps[i] == nullptr) { @@ -243,17 +243,13 @@ static int StatusChange(WPARAM wParam, LPARAM lParam) { char *szProto = (char *)lParam; if (szProto == nullptr) { // global status change - for (int i = 0; i < protoList.getCount(); i++) { - SMProto &cs = protoList[i]; - cs.AssignStatus(wParam, 0, cs.m_szMsg); - } + for (auto &it : protoList) + it->AssignStatus(wParam, 0, it->m_szMsg); } else { - for (int i = 0; i < protoList.getCount(); i++) { - SMProto &cs = protoList[i]; - if (!mir_strcmp(cs.m_szName, szProto)) - cs.AssignStatus(wParam, 0, cs.m_szMsg); - } + for (auto &it : protoList) + if (!mir_strcmp(it->m_szName, szProto)) + it->AssignStatus(wParam, 0, it->m_szMsg); } return 0; @@ -272,13 +268,12 @@ static int CSStatusChange(WPARAM wParam, LPARAM) if (psi->szName == nullptr) continue; - for (int j = 0; j < protoList.getCount(); j++) { - SMProto &cs = protoList[i]; - if (cs.m_szName == nullptr) + for (auto &it : protoList) { + if (it->m_szName == nullptr) continue; - if (!mir_strcmp(psi->szName, cs.m_szName)) - cs.AssignStatus(psi->status, psi->lastStatus, cs.m_szMsg); + if (!mir_strcmp(psi->szName, it->m_szName)) + it->AssignStatus(psi->status, psi->lastStatus, it->m_szMsg); } } } @@ -299,13 +294,12 @@ static int CSStatusChangeEx(WPARAM wParam, LPARAM) if (psi->m_szName == nullptr) continue; - for (int j = 0; j < protoList.getCount(); j++) { - SMProto &cs = protoList[i]; - if (cs.m_szName == nullptr) + for (auto &it : protoList) { + if (it->m_szName == nullptr) continue; - if (!mir_strcmp(psi->m_szName, cs.m_szName)) - cs.AssignStatus(psi->m_status, psi->m_lastStatus, psi->m_szMsg); + if (!mir_strcmp(psi->m_szName, it->m_szName)) + it->AssignStatus(psi->m_status, psi->m_lastStatus, psi->m_szMsg); } } } @@ -482,28 +476,26 @@ static int ProcessProtoAck(WPARAM, LPARAM lParam) return 0; if (ack->type == ACKTYPE_STATUS && ack->result == ACKRESULT_SUCCESS) { - for (int i = 0; i < protoList.getCount(); i++) { - SMProto &cs = protoList[i]; - if (!mir_strcmp(cs.m_szName, ack->szModule)) - cs.lastStatusAckTime = GetTickCount(); - } + for (auto &it : protoList) + if (!mir_strcmp(it->m_szName, ack->szModule)) + it->lastStatusAckTime = GetTickCount(); + StartTimer(IDT_PROCESSACK, 0, FALSE); return 0; } if (ack->type == ACKTYPE_LOGIN) { if (ack->lParam == LOGINERR_OTHERLOCATION) { - for (int i = 0; i < protoList.getCount(); i++) { - SMProto &cs = protoList[i]; - if (!mir_strcmp(ack->szModule, cs.m_szName)) { - cs.AssignStatus(ID_STATUS_OFFLINE); + for (auto &it : protoList) { + if (!mir_strcmp(ack->szModule, it->m_szName)) { + it->AssignStatus(ID_STATUS_OFFLINE); if (db_get_b(0, KSMODULENAME, SETTING_CNCOTHERLOC, 0)) { StopTimer(IDT_PROCESSACK); - for (int j = 0; j < protoList.getCount(); j++) - protoList[j].AssignStatus(ID_STATUS_OFFLINE); + for (auto &jt : protoList) + jt->AssignStatus(ID_STATUS_OFFLINE); } - NotifyEventHooks(hConnectionEvent, (WPARAM)KS_CONN_STATE_OTHERLOCATION, (LPARAM)cs.m_szName); + NotifyEventHooks(hConnectionEvent, (WPARAM)KS_CONN_STATE_OTHERLOCATION, (LPARAM)it->m_szName); ProcessPopup(KS_CONN_STATE_OTHERLOCATION, (LPARAM)ack->szModule); } } @@ -515,11 +507,10 @@ static int ProcessProtoAck(WPARAM, LPARAM lParam) switch (db_get_b(0, KSMODULENAME, SETTING_LOGINERR, LOGINERR_NOTHING)) { case LOGINERR_CANCEL: log_infoA("KeepStatus: cancel on login error (%s)", ack->szModule); - for (int i = 0; i < protoList.getCount(); i++) { - SMProto &cs = protoList[i]; - if (!mir_strcmp(ack->szModule, cs.m_szName)) - cs.AssignStatus(ID_STATUS_OFFLINE); - } + for (auto &it : protoList) + if (!mir_strcmp(ack->szModule, it->m_szName)) + it->AssignStatus(ID_STATUS_OFFLINE); + ProcessPopup(KS_CONN_STATE_LOGINERROR, (LPARAM)ack->szModule); StopChecking(); break; @@ -548,17 +539,15 @@ static VOID CALLBACK CheckConnectingTimer(HWND, UINT, UINT_PTR, DWORD) { StopTimer(IDT_CHECKCONNECTING); - for (int i = 0; i < protoList.getCount(); i++) { - SMProto &cs = protoList[i]; - - int curStatus = cs.GetStatus(); + for (auto &it : protoList) { + int curStatus = it->GetStatus(); if (IsStatusConnecting(curStatus)) { // connecting int maxConnectingTime = db_get_dw(0, KSMODULENAME, SETTING_MAXCONNECTINGTIME, 0); if (maxConnectingTime > 0) { - if ((unsigned int)maxConnectingTime <= ((GetTickCount() - cs.lastStatusAckTime) / 1000)) { + if ((unsigned int)maxConnectingTime <= ((GetTickCount() - it->lastStatusAckTime) / 1000)) { // set offline - log_infoA("KeepStatus: %s is too long connecting; setting offline", cs.m_szName); - CallProtoService(cs.m_szName, PS_SETSTATUS, (WPARAM)ID_STATUS_OFFLINE, 0); + log_infoA("KeepStatus: %s is too long connecting; setting offline", it->m_szName); + CallProtoService(it->m_szName, PS_SETSTATUS, (WPARAM)ID_STATUS_OFFLINE, 0); } } } @@ -570,11 +559,9 @@ static VOID CALLBACK CheckAckStatusTimer(HWND, UINT, UINT_PTR, DWORD) bool needChecking = false; StopTimer(IDT_PROCESSACK); - for (int i = 0; i < protoList.getCount(); i++) { - SMProto &cs = protoList[i]; - - int curStatus = cs.GetStatus(); - int newStatus = CallProtoService(cs.m_szName, PS_GETSTATUS, 0, 0); + for (auto &it : protoList) { + int curStatus = it->GetStatus(); + int newStatus = CallProtoService(it->m_szName, PS_GETSTATUS, 0, 0); // ok, np if (curStatus == ID_STATUS_CURRENT || curStatus == ID_STATUS_DISABLED || curStatus == newStatus || newStatus > MAX_STATUS) continue; @@ -582,19 +569,19 @@ static VOID CALLBACK CheckAckStatusTimer(HWND, UINT, UINT_PTR, DWORD) if (IsStatusConnecting(newStatus)) { // connecting int maxConnectingTime = db_get_dw(0, KSMODULENAME, SETTING_MAXCONNECTINGTIME, 0); if (maxConnectingTime > 0) - StartTimer(IDT_CHECKCONNECTING, (maxConnectingTime * 1000 - (GetTickCount() - cs.lastStatusAckTime)), FALSE); + StartTimer(IDT_CHECKCONNECTING, (maxConnectingTime * 1000 - (GetTickCount() - it->lastStatusAckTime)), FALSE); } // keepstatus' administration was wrong! else if (newStatus != ID_STATUS_OFFLINE) - cs.AssignStatus(newStatus); + it->AssignStatus(newStatus); // connection lost else if (newStatus == ID_STATUS_OFFLINE) {// start checking connection if (!StartTimer(IDT_CHECKCONN, -1, FALSE)) { /* check if not already checking */ needChecking = true; - log_infoA("KeepStatus: connection lost! (%s)", cs.m_szName); - NotifyEventHooks(hConnectionEvent, (WPARAM)KS_CONN_STATE_LOST, (LPARAM)cs.m_szName); - ProcessPopup(KS_CONN_STATE_LOST, (LPARAM)cs.m_szName); + log_infoA("KeepStatus: connection lost! (%s)", it->m_szName); + NotifyEventHooks(hConnectionEvent, (WPARAM)KS_CONN_STATE_LOST, (LPARAM)it->m_szName); + ProcessPopup(KS_CONN_STATE_LOST, (LPARAM)it->m_szName); } } } @@ -608,16 +595,17 @@ static VOID CALLBACK CheckConnectionTimer(HWND, UINT, UINT_PTR, DWORD) log_debugA("CheckConnectionTimer"); bool setStatus = false; - for (int i = 0; i < protoList.getCount() && !setStatus; i++) { - SMProto &cs = protoList[i]; - int realStatus = CallProtoService(cs.m_szName, PS_GETSTATUS, 0, 0); - int shouldBeStatus = cs.GetStatus(); + for (auto &it : protoList) { + int realStatus = CallProtoService(it->m_szName, PS_GETSTATUS, 0, 0); + int shouldBeStatus = it->GetStatus(); if (shouldBeStatus == ID_STATUS_LAST) - shouldBeStatus = cs.m_lastStatus; + shouldBeStatus = it->m_lastStatus; if (shouldBeStatus == ID_STATUS_DISABLED) continue; - if ((shouldBeStatus != realStatus) && (realStatus == ID_STATUS_OFFLINE) || (realStatus < MIN_STATUS)) + if ((shouldBeStatus != realStatus) && (realStatus == ID_STATUS_OFFLINE) || (realStatus < MIN_STATUS)) { setStatus = true; + break; + } } // one of the status was wrong @@ -649,13 +637,13 @@ static int StopChecking() StopTimer(IDT_CHECKCONN | IDT_PROCESSACK | IDT_AFTERCHECK | IDT_CHECKCONNECTING); BOOL isOk = TRUE; - for (int i = 0; i < protoList.getCount() && isOk; i++) { - SMProto &cs = protoList[i]; - int curStatus = cs.GetStatus(); - int newStatus = CallProtoService(cs.m_szName, PS_GETSTATUS, 0, 0); + for (auto &it : protoList) { + int curStatus = it->GetStatus(); + int newStatus = CallProtoService(it->m_szName, PS_GETSTATUS, 0, 0); if (newStatus != curStatus) { - cs.AssignStatus(newStatus); + it->AssignStatus(newStatus); isOk = FALSE; + break; } } @@ -675,12 +663,11 @@ static VOID CALLBACK AfterCheckTimer(HWND, UINT, UINT_PTR, DWORD) bool setStatus = false; - for (int i = 0; i < protoList.getCount(); i++) { - SMProto &cs = protoList[i]; - int realStatus = CallProtoService(cs.m_szName, PS_GETSTATUS, 0, 0); - int shouldBeStatus = cs.GetStatus(); + for (auto &it : protoList) { + int realStatus = CallProtoService(it->m_szName, PS_GETSTATUS, 0, 0); + int shouldBeStatus = it->GetStatus(); if (shouldBeStatus == ID_STATUS_LAST) // this should never happen - shouldBeStatus = cs.m_lastStatus; + shouldBeStatus = it->m_lastStatus; if (shouldBeStatus == ID_STATUS_DISABLED) // (on ignoring proto) continue; if ((shouldBeStatus != realStatus) && (realStatus == ID_STATUS_OFFLINE) || (realStatus < MIN_STATUS)) @@ -702,17 +689,16 @@ static void CheckContinuouslyFunction(void *) // do a ping, even if reconnecting bool doPing = false; - for (int i = 0; i < protoList.getCount(); i++) { - SMProto &cs = protoList[i]; - int shouldBeStatus = cs.GetStatus(); + for (auto &it : protoList) { + int shouldBeStatus = it->GetStatus(); if (shouldBeStatus == ID_STATUS_LAST) - shouldBeStatus = cs.m_lastStatus; + shouldBeStatus = it->m_lastStatus; if (shouldBeStatus == ID_STATUS_DISABLED) continue; if (shouldBeStatus != ID_STATUS_OFFLINE) { - log_debugA("CheckContinuouslyFunction: %s should be %d", cs.m_szName, shouldBeStatus); + log_debugA("CheckContinuouslyFunction: %s should be %d", it->m_szName, shouldBeStatus); doPing = true; } } @@ -1005,13 +991,12 @@ INT_PTR EnableProtocolService(WPARAM wParam, LPARAM lParam) return -1; int ret = -2; - for (int i = 0; i < protoList.getCount(); i++) { - SMProto &cs = protoList[i]; - if (!mir_strcmp(szProto, cs.m_szName)) { + for (auto &it : protoList) { + if (!mir_strcmp(szProto, it->m_szName)) { if (wParam) - cs.AssignStatus(CallProtoService(cs.m_szName, PS_GETSTATUS, 0, 0)); + it->AssignStatus(CallProtoService(it->m_szName, PS_GETSTATUS, 0, 0)); else - cs.AssignStatus(ID_STATUS_DISABLED); + it->AssignStatus(ID_STATUS_DISABLED); ret = 0; break; @@ -1029,11 +1014,9 @@ INT_PTR IsProtocolEnabledService(WPARAM, LPARAM lParam) if (!db_get_b(0, KSMODULENAME, dbSetting, 1)) return FALSE; - for (int i = 0; i < protoList.getCount(); i++) { - SMProto &cs = protoList[i]; - if (!mir_strcmp(szProto, cs.m_szName)) - return cs.GetStatus() != ID_STATUS_DISABLED; - } + for (auto &it : protoList) + if (!mir_strcmp(szProto, it->m_szName)) + return it->GetStatus() != ID_STATUS_DISABLED; return FALSE; } @@ -1043,11 +1026,9 @@ INT_PTR AnnounceStatusChangeService(WPARAM, LPARAM lParam) PROTOCOLSETTINGEX *newSituation = (PROTOCOLSETTINGEX *)lParam; log_infoA("Another plugin announced a status change to %d for %s", newSituation->m_status, newSituation->m_szName == nullptr ? "all" : newSituation->m_szName); - for (int i = 0; i < protoList.getCount(); i++) { - SMProto &cs = protoList[i]; - if (!mir_strcmp(cs.m_szName, newSituation->m_szName)) - cs.AssignStatus(newSituation->m_status, newSituation->m_lastStatus, newSituation->m_szMsg); - } + for (auto &it : protoList) + if (!mir_strcmp(it->m_szName, newSituation->m_szName)) + it->AssignStatus(newSituation->m_status, newSituation->m_lastStatus, newSituation->m_szMsg); return 0; } diff --git a/plugins/StatusManager/src/StartupStatus/ss_options.cpp b/plugins/StatusManager/src/StartupStatus/ss_options.cpp index c0253b26e1..c3400120bd 100644 --- a/plugins/StatusManager/src/StartupStatus/ss_options.cpp +++ b/plugins/StatusManager/src/StartupStatus/ss_options.cpp @@ -109,23 +109,21 @@ static wchar_t* GetLinkDescription(TProtoSettings& protoSettings) return nullptr; CMStringW result(SHORTCUT_DESC); - for (int i = 0; i < protoSettings.getCount(); i++) { - SMProto &p = protoSettings[i]; - + for (auto &p : protoSettings) { wchar_t *status; - if (p.m_status == ID_STATUS_LAST) + if (p->m_status == ID_STATUS_LAST) status = TranslateT("<last>"); - else if (p.m_status == ID_STATUS_CURRENT) + else if (p->m_status == ID_STATUS_CURRENT) status = TranslateT("<current>"); - else if (p.m_status >= MIN_STATUS && p.m_status <= MAX_STATUS) - status = pcli->pfnGetStatusModeDescription(p.m_status, 0); + else if (p->m_status >= MIN_STATUS && p->m_status <= MAX_STATUS) + status = pcli->pfnGetStatusModeDescription(p->m_status, 0); else status = nullptr; if (status == nullptr) status = TranslateT("<unknown>"); result.AppendChar('\r'); - result.Append(p.m_tszAccName); + result.Append(p->m_tszAccName); result.AppendChar(':'); result.AppendChar(' '); result.Append(status); @@ -525,9 +523,8 @@ class CSSAdvancedOptDlg : public CDlgBase // fill proto list lstAccount.ResetContent(); - TProtoSettings &ar = arProfiles[sel].ps; - for (int i = 0; i < ar.getCount(); i++) - lstAccount.AddString(ar[i].m_tszAccName, (LPARAM)&ar[i]); + for (auto &it : arProfiles[sel].ps) + lstAccount.AddString(it->m_tszAccName, (LPARAM)it); lstAccount.SetCurSel(0); SetProtocol(); @@ -684,10 +681,10 @@ public: char setting[128]; int len = mir_snprintf(setting, "%d_", i); - for (int k = 0; k < arSettings.getCount(); k++) { - if (!strncmp(setting, arSettings[k], len)) - db_unset(0, SSMODULENAME, arSettings[k]); - mir_free(arSettings[k]); + for (auto &it : arSettings) { + if (!strncmp(setting, it, len)) + db_unset(0, SSMODULENAME, it); + mir_free(it); } } diff --git a/plugins/StatusManager/src/StartupStatus/ss_profiles.cpp b/plugins/StatusManager/src/StartupStatus/ss_profiles.cpp index 872139fc83..608cface96 100644 --- a/plugins/StatusManager/src/StartupStatus/ss_profiles.cpp +++ b/plugins/StatusManager/src/StartupStatus/ss_profiles.cpp @@ -133,11 +133,10 @@ wchar_t* GetStatusMessage(int profile, const char *szProto) char dbSetting[80]; mir_snprintf(dbSetting, "%d_%s_%s", profile, szProto, SETTING_PROFILE_STSMSG); - for (int i = 0; i < arProfiles.getCount(); i++) { - auto &p = arProfiles[i]; - if (p.profile == profile && !mir_strcmp(p.szProto, szProto)) { - p.msg = db_get_wsa(0, SSMODULENAME, dbSetting); - return p.msg; + for (auto &p : arProfiles) { + if (p->profile == profile && !mir_strcmp(p->szProto, szProto)) { + p->msg = db_get_wsa(0, SSMODULENAME, dbSetting); + return p->msg; } } @@ -181,8 +180,8 @@ int GetProfile(int profile, TProtoSettings &arSettings) if (profile >= count && count > 0) return -1; - for (int i = 0; i < arSettings.getCount(); i++) - FillStatus(arSettings[i], profile); + for (auto &it : arSettings) + FillStatus(*it, profile); return (arSettings.getCount() == 0) ? -1 : 0; } diff --git a/plugins/StatusManager/src/StartupStatus/startupstatus.cpp b/plugins/StatusManager/src/StartupStatus/startupstatus.cpp index f4d6df4150..0c44c09a9c 100644 --- a/plugins/StatusManager/src/StartupStatus/startupstatus.cpp +++ b/plugins/StatusManager/src/StartupStatus/startupstatus.cpp @@ -37,9 +37,9 @@ static BYTE showDialogOnStartup = 0; static PROTOCOLSETTINGEX* IsValidProtocol(TProtoSettings &protoSettings, const char *protoName) { - for (int i = 0; i < protoSettings.getCount(); i++) - if (!strncmp(protoSettings[i].m_szName, protoName, mir_strlen(protoSettings[i].m_szName))) - return &protoSettings[i]; + for (auto &it : protoSettings) + if (!strncmp(it->m_szName, protoName, mir_strlen(it->m_szName))) + return it; return nullptr; } @@ -117,13 +117,13 @@ static void ProcessCommandLineOptions(TProtoSettings& protoSettings) static void SetLastStatusMessages(TProtoSettings &ps) { - for (int i = 0; i < ps.getCount(); i++) { - if (ps[i].m_status != ID_STATUS_LAST) + for (auto &it : ps) { + if (it->m_status != ID_STATUS_LAST) continue; char dbSetting[128]; - mir_snprintf(dbSetting, "%s%s", PREFIX_LASTMSG, ps[i].m_szName); - ps[i].m_szMsg = db_get_wsa(0, SSMODULENAME, dbSetting); + mir_snprintf(dbSetting, "%s%s", PREFIX_LASTMSG, it->m_szName); + it->m_szMsg = db_get_wsa(0, SSMODULENAME, dbSetting); } } @@ -141,9 +141,9 @@ static int ProcessProtoAck(WPARAM, LPARAM lParam) if (!db_get_b(0, SSMODULENAME, SETTING_OVERRIDE, 1) || protoList.getCount() == 0) return 0; - for (int i = 0; i < protoList.getCount(); i++) { - if (!mir_strcmp(ack->szModule, protoList[i].m_szName)) { - protoList[i].m_szName = ""; + for (auto &it : protoList) { + if (!mir_strcmp(ack->szModule, it->m_szName)) { + it->m_szName = ""; log_debugA("StartupStatus: %s overridden by ME_PROTO_ACK, status will not be set", ack->szModule); } } @@ -159,15 +159,15 @@ static int StatusChange(WPARAM, LPARAM lParam) char *szProto = (char *)lParam; if (szProto == nullptr) { // global status change - for (int i = 0; i < protoList.getCount(); i++) { - protoList[i].m_szName = ""; + for (auto &it : protoList) { + it->m_szName = ""; log_debugA("StartupStatus: all protos overridden by ME_CLIST_STATUSMODECHANGE, status will not be set"); } } else { - for (int i = 0; i < protoList.getCount(); i++) { - if (!mir_strcmp(protoList[i].m_szName, szProto)) { - protoList[i].m_szName = ""; + for (auto &it : protoList) { + if (!mir_strcmp(it->m_szName, szProto)) { + it->m_szName = ""; log_debugA("StartupStatus: %s overridden by ME_CLIST_STATUSMODECHANGE, status will not be set", szProto); } } diff --git a/plugins/StatusManager/src/commonstatus.cpp b/plugins/StatusManager/src/commonstatus.cpp index 702d2cea26..6355cc9839 100644 --- a/plugins/StatusManager/src/commonstatus.cpp +++ b/plugins/StatusManager/src/commonstatus.cpp @@ -60,8 +60,8 @@ TProtoSettings::TProtoSettings() TProtoSettings::TProtoSettings(const TProtoSettings &p) : OBJLIST<SMProto>(p.getCount(), CompareProtoSettings) { - for (int i = 0; i < p.getCount(); i++) - insert(new SMProto(p[i])); + for (auto &it : p) + insert(new SMProto(*it)); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -145,17 +145,17 @@ wchar_t* GetDefaultStatusMessage(PROTOCOLSETTINGEX *ps, int newstatus) static int equalsGlobalStatus(PROTOCOLSETTINGEX **ps) { - int i, j, pstatus = 0, gstatus = 0; + int j, pstatus = 0, gstatus = 0; - for (i = 0; i < protoList.getCount(); i++) - if (ps[i]->m_szMsg != nullptr && GetActualStatus(ps[i]) != ID_STATUS_OFFLINE) + for (auto &it : protoList) + if (it->m_szMsg != nullptr && GetActualStatus(it) != ID_STATUS_OFFLINE) return 0; int count; PROTOACCOUNT **protos; Proto_EnumAccounts(&count, &protos); - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { if (!IsSuitableProto(protos[i])) continue; diff --git a/plugins/StatusManager/src/confirmdialog.cpp b/plugins/StatusManager/src/confirmdialog.cpp index 0d3ce3e2a3..5cdcf88237 100644 --- a/plugins/StatusManager/src/confirmdialog.cpp +++ b/plugins/StatusManager/src/confirmdialog.cpp @@ -112,19 +112,19 @@ static int SetStatusList(HWND hwndDlg) LVITEM lvItem = { 0 }; lvItem.mask = LVIF_TEXT | LVIF_PARAM; - for (int i = 0; i < confirmSettings->getCount(); i++) { - lvItem.pszText = (*confirmSettings)[i].m_tszAccName; + for (auto &it : *confirmSettings) { + lvItem.pszText = it->m_tszAccName; if (ListView_GetItemCount(hList) < confirmSettings->getCount()) ListView_InsertItem(hList, &lvItem); int actualStatus; - switch ((*confirmSettings)[i].m_status) { - case ID_STATUS_LAST: actualStatus = (*confirmSettings)[i].m_lastStatus; break; - case ID_STATUS_CURRENT: actualStatus = CallProtoService((*confirmSettings)[i].m_szName, PS_GETSTATUS, 0, 0); break; - default: actualStatus = (*confirmSettings)[i].m_status; + switch (it->m_status) { + case ID_STATUS_LAST: actualStatus = it->m_lastStatus; break; + case ID_STATUS_CURRENT: actualStatus = CallProtoService(it->m_szName, PS_GETSTATUS, 0, 0); break; + default: actualStatus = it->m_status; } - wchar_t* status = pcli->pfnGetStatusModeDescription(actualStatus, 0); - switch ((*confirmSettings)[i].m_status) { + wchar_t *status = pcli->pfnGetStatusModeDescription(actualStatus, 0); + switch (it->m_status) { case ID_STATUS_LAST: mir_snwprintf(buf, L"%s (%s)", TranslateT("<last>"), status); ListView_SetItemText(hList, lvItem.iItem, 1, buf); @@ -138,10 +138,10 @@ static int SetStatusList(HWND hwndDlg) } // status message - if (!((!((CallProtoService((*confirmSettings)[i].m_szName, PS_GETCAPS, (WPARAM)PFLAGNUM_1, 0)&PF1_MODEMSGSEND)&~PF1_INDIVMODEMSG)) || (!(CallProtoService((*confirmSettings)[i].m_szName, PS_GETCAPS, (WPARAM)PFLAGNUM_3, 0)&Proto_Status2Flag(actualStatus))))) { - wchar_t *msg = GetDefaultStatusMessage(&(*confirmSettings)[i], actualStatus); + if (!((!((CallProtoService(it->m_szName, PS_GETCAPS, (WPARAM)PFLAGNUM_1, 0)&PF1_MODEMSGSEND)&~PF1_INDIVMODEMSG)) || (!(CallProtoService(it->m_szName, PS_GETCAPS, (WPARAM)PFLAGNUM_3, 0)&Proto_Status2Flag(actualStatus))))) { + wchar_t *msg = GetDefaultStatusMessage(it, actualStatus); if (msg != nullptr) { - wchar_t* fMsg = variables_parsedup(msg, (*confirmSettings)[i].m_tszAccName, 0); + wchar_t* fMsg = variables_parsedup(msg, it->m_tszAccName, 0); ListView_SetItemText(hList, lvItem.iItem, 2, fMsg); mir_free(fMsg); mir_free(msg); @@ -152,7 +152,7 @@ static int SetStatusList(HWND hwndDlg) ListView_SetColumnWidth(hList, 0, LVSCW_AUTOSIZE); ListView_SetColumnWidth(hList, 2, LVSCW_AUTOSIZE); - lvItem.lParam = (LPARAM)&(*confirmSettings)[i]; + lvItem.lParam = (LPARAM)it; ListView_SetItem(hList, &lvItem); lvItem.iItem++; } @@ -238,12 +238,12 @@ static INT_PTR CALLBACK ConfirmDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP case IDC_PROFILE: { int profile = (int)SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0), 0); - for (int i = 0; i < confirmSettings->getCount(); i++) - replaceStrW((*confirmSettings)[i].m_szMsg, nullptr); + for (auto &it : *confirmSettings) + replaceStrW(it->m_szMsg, nullptr); CallService(MS_SS_GETPROFILE, (WPARAM)profile, (LPARAM)confirmSettings); - for (int i = 0; i < confirmSettings->getCount(); i++) - (*confirmSettings)[i].m_szMsg = mir_wstrdup((*confirmSettings)[i].m_szMsg); + for (auto &it : *confirmSettings) + it->m_szMsg = mir_wstrdup(it->m_szMsg); SetStatusList(hwndDlg); } @@ -402,8 +402,8 @@ HWND ShowConfirmDialogEx(TProtoSettings *params, int _timeout) delete confirmSettings; confirmSettings = new OBJLIST<TConfirmSetting>(10, CompareSettings); - for (int i = 0; i < params->getCount(); i++) - confirmSettings->insert(new TConfirmSetting((*params)[i])); + for (auto &it : *params) + confirmSettings->insert(new TConfirmSetting(*it)); timeOut = _timeout; if (timeOut < 0) diff --git a/plugins/StatusManager/src/main.cpp b/plugins/StatusManager/src/main.cpp index 478112b6af..651123f71c 100644 --- a/plugins/StatusManager/src/main.cpp +++ b/plugins/StatusManager/src/main.cpp @@ -103,9 +103,9 @@ int OnAccChanged(WPARAM wParam, LPARAM lParam) break; case PRAC_REMOVED: - for (int i = 0; i < protoList.getCount(); i++) { - if (!mir_strcmp(protoList[i].m_szName, pa->szModuleName)) { - protoList.remove(i); + for (auto &it : protoList) { + if (!mir_strcmp(it->m_szName, pa->szModuleName)) { + protoList.remove(it); break; } } |