From 39390b02dbd5aa7eb21a83773fa561b39f8828bc Mon Sep 17 00:00:00 2001 From: George Hazan <ghazan@miranda.im> Date: Fri, 16 Mar 2018 20:01:14 +0300 Subject: always hated these long expressions: contact_iter makes them much shorter --- plugins/NewsAggregator/Src/Options.cpp | 10 +++++----- plugins/NewsAggregator/Src/Services.cpp | 6 +++--- plugins/NewsAggregator/Src/Update.cpp | 2 +- plugins/NewsAggregator/Src/Utils.cpp | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) (limited to 'plugins/NewsAggregator') diff --git a/plugins/NewsAggregator/Src/Options.cpp b/plugins/NewsAggregator/Src/Options.cpp index 8fc2685e8c..4d43ddcbc4 100644 --- a/plugins/NewsAggregator/Src/Options.cpp +++ b/plugins/NewsAggregator/Src/Options.cpp @@ -39,7 +39,7 @@ CExportFeed::CExportFeed() void CExportFeed::OnInitDialog() { Utils_RestoreWindowPositionNoSize(m_hwnd, NULL, MODULE, "ExportDlg"); - for (MCONTACT hContact = db_find_first(MODULE); hContact; hContact = db_find_next(hContact, MODULE)) { + for (auto &hContact : contact_iter(MODULE)) { wchar_t *message = db_get_wsa(hContact, MODULE, "Nick"); if (message != nullptr) { m_feedslist.AddString(message); @@ -692,7 +692,7 @@ void CFeedEditor::OnInitDialog() m_list->GetItemText(m_iItem, 0, SelNick, _countof(SelNick)); m_list->GetItemText(m_iItem, 1, SelUrl, _countof(SelNick)); - for (MCONTACT hContact = db_find_first(MODULE); hContact; hContact = db_find_next(hContact, MODULE)) { + for (auto &hContact : contact_iter(MODULE)) { ptrW dbNick(db_get_wsa(hContact, MODULE, "Nick")); if ((dbNick == NULL) || (mir_wstrcmp(dbNick, SelNick) != 0)) continue; @@ -874,7 +874,7 @@ void CFeedEditor::OnUseAuth(CCtrlBase*) void COptionsMain::UpdateList() { - for (MCONTACT hContact = db_find_first(MODULE); hContact; hContact = db_find_next(hContact, MODULE)) { + for (auto &hContact : contact_iter(MODULE)) { UpdateListFlag = TRUE; wchar_t *ptszNick = db_get_wsa(hContact, MODULE, "Nick"); if (ptszNick) { @@ -928,7 +928,7 @@ void COptionsMain::OnInitDialog() void COptionsMain::OnApply() { - for (MCONTACT hContact = db_find_first(MODULE); hContact; hContact = db_find_next(hContact, MODULE)) { + for (auto &hContact : contact_iter(MODULE)) { ptrW dbNick(db_get_wsa(hContact, MODULE, "Nick")); for (int i = 0; i < m_feeds.GetItemCount(); i++) { wchar_t nick[MAX_PATH]; @@ -998,7 +998,7 @@ void COptionsMain::OnDeleteButtonClick(CCtrlBase*) m_feeds.GetItemText(isel, 0, nick, _countof(nick)); m_feeds.GetItemText(isel, 1, url, _countof(url)); - for (MCONTACT hContact = db_find_first(MODULE); hContact; hContact = db_find_next(hContact, MODULE)) { + for (auto &hContact : contact_iter(MODULE)) { ptrW dbNick(db_get_wsa(hContact, MODULE, "Nick")); if (dbNick == NULL) break; diff --git a/plugins/NewsAggregator/Src/Services.cpp b/plugins/NewsAggregator/Src/Services.cpp index 8999731766..8be70f3541 100644 --- a/plugins/NewsAggregator/Src/Services.cpp +++ b/plugins/NewsAggregator/Src/Services.cpp @@ -36,7 +36,7 @@ int NewsAggrInit(WPARAM, LPARAM) else mir_wstrncpy(tszRoot, VARSW(L"%miranda_userdata%\\Avatars\\" _A2W(DEFAULT_AVATARS_FOLDER)), _countof(tszRoot)); - for (MCONTACT hContact = db_find_first(MODULE); hContact; hContact = db_find_next(hContact, MODULE)) { + for (auto &hContact : contact_iter(MODULE)) { if (!db_get_b(NULL, MODULE, "StartupRetrieve", 1)) db_set_dw(hContact, MODULE, "LastCheck", time(nullptr)); db_set_w(hContact, MODULE, "Status", ID_STATUS_ONLINE); @@ -98,7 +98,7 @@ INT_PTR NewsAggrSetStatus(WPARAM wp, LPARAM) if(nStatus != g_nStatus) { g_nStatus = nStatus; - for (MCONTACT hContact = db_find_first(MODULE); hContact; hContact = db_find_next(hContact, MODULE)) + for (auto &hContact : contact_iter(MODULE)) db_set_w(hContact, MODULE, "Status", nStatus); ProtoBroadcastAck(MODULE, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)nOldStatus, g_nStatus); @@ -133,7 +133,7 @@ INT_PTR NewsAggrGetInfo(WPARAM, LPARAM lParam) INT_PTR CheckAllFeeds(WPARAM, LPARAM lParam) { - for (MCONTACT hContact = db_find_first(MODULE); hContact; hContact = db_find_next(hContact, MODULE)) { + for (auto &hContact : contact_iter(MODULE)) { if (lParam && db_get_dw(hContact, MODULE, "UpdateTime", DEFAULT_UPDATE_TIME)) UpdateListAdd(hContact); else if (!lParam) diff --git a/plugins/NewsAggregator/Src/Update.cpp b/plugins/NewsAggregator/Src/Update.cpp index 56c0d2f44d..feaaf9840d 100644 --- a/plugins/NewsAggregator/Src/Update.cpp +++ b/plugins/NewsAggregator/Src/Update.cpp @@ -30,7 +30,7 @@ void CALLBACK timerProc(HWND, UINT, UINT_PTR, DWORD) // only run if it is not current updating and the auto update option is enabled if (!ThreadRunning && !Miranda_IsTerminated()) { bool HaveUpdates = FALSE; - for (MCONTACT hContact = db_find_first(MODULE); hContact; hContact = db_find_next(hContact, MODULE)) { + for (auto &hContact : contact_iter(MODULE)) { if (db_get_dw(hContact, MODULE, "UpdateTime", DEFAULT_UPDATE_TIME)) { double diff = difftime(time(nullptr), (time_t)db_get_dw(hContact, MODULE, "LastCheck", 0)); if (db_get_b(NULL, MODULE, "AutoUpdate", 1) != 0 && diff >= db_get_dw(hContact, MODULE, "UpdateTime", DEFAULT_UPDATE_TIME) * 60) { diff --git a/plugins/NewsAggregator/Src/Utils.cpp b/plugins/NewsAggregator/Src/Utils.cpp index b6da7a9e0a..d2e646c5e8 100644 --- a/plugins/NewsAggregator/Src/Utils.cpp +++ b/plugins/NewsAggregator/Src/Utils.cpp @@ -431,7 +431,7 @@ MCONTACT GetContactByNick(const wchar_t *nick) { MCONTACT hContact = NULL; - for (hContact = db_find_first(MODULE); hContact; hContact = db_find_next(hContact, MODULE)) { + for (auto &hContact : contact_iter(MODULE)) { ptrW contactNick(::db_get_wsa(hContact, MODULE, "Nick")); if (!mir_wstrcmpi(contactNick, nick)) break; @@ -443,7 +443,7 @@ MCONTACT GetContactByURL(const wchar_t *url) { MCONTACT hContact = NULL; - for (hContact = db_find_first(MODULE); hContact; hContact = db_find_next(hContact, MODULE)) { + for (auto &hContact : contact_iter(MODULE)) { ptrW contactURL(::db_get_wsa(hContact, MODULE, "URL")); if (!mir_wstrcmpi(contactURL, url)) break; -- cgit v1.2.3