From 39390b02dbd5aa7eb21a83773fa561b39f8828bc Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 16 Mar 2018 20:01:14 +0300 Subject: always hated these long expressions: contact_iter makes them much shorter --- src/mir_app/src/DefaultExtraIcons.cpp | 2 +- src/mir_app/src/ExtraIcon.cpp | 2 +- src/mir_app/src/chat_clist.cpp | 6 ++---- src/mir_app/src/clc.cpp | 12 ++++++------ src/mir_app/src/clcitems.cpp | 4 ++-- src/mir_app/src/clistgroups.cpp | 4 ++-- src/mir_app/src/contact.cpp | 2 +- src/mir_app/src/ignore.cpp | 4 ++-- src/mir_app/src/meta_addto.cpp | 2 +- src/mir_app/src/meta_main.cpp | 2 +- src/mir_app/src/meta_utils.cpp | 8 ++++---- src/mir_app/src/mir_app.def | 1 + src/mir_app/src/mir_app64.def | 1 + src/mir_app/src/options_ei.cpp | 2 +- src/mir_app/src/proto_utils.cpp | 2 +- src/mir_app/src/visibility.cpp | 4 ++-- 16 files changed, 29 insertions(+), 29 deletions(-) (limited to 'src/mir_app') diff --git a/src/mir_app/src/DefaultExtraIcons.cpp b/src/mir_app/src/DefaultExtraIcons.cpp index 26e9ae9d1f..ec4e4315c2 100644 --- a/src/mir_app/src/DefaultExtraIcons.cpp +++ b/src/mir_app/src/DefaultExtraIcons.cpp @@ -312,7 +312,7 @@ void DefaultExtraIcons_Load() p.hExtraIcon = ExtraIcon_RegisterIcolib(p.name, p.desc, Skin_GetIconName(p.iSkinIcon), nullptr, 0, p.flags); } - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { SetExtraIcons(hContact); SetVisibility(hContact, -1, false); SetGender(hContact, -1, false); diff --git a/src/mir_app/src/ExtraIcon.cpp b/src/mir_app/src/ExtraIcon.cpp index a22b28b6ac..95d093feaf 100644 --- a/src/mir_app/src/ExtraIcon.cpp +++ b/src/mir_app/src/ExtraIcon.cpp @@ -67,7 +67,7 @@ void ExtraIcon::applyIcons() if (!isEnabled()) return; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { // Clear to assert that it will be cleared Clist_SetExtraIcon(hContact, m_slot, INVALID_HANDLE_VALUE); applyIcon(hContact); diff --git a/src/mir_app/src/chat_clist.cpp b/src/mir_app/src/chat_clist.cpp index e1d20e01bf..5fb50bca59 100644 --- a/src/mir_app/src/chat_clist.cpp +++ b/src/mir_app/src/chat_clist.cpp @@ -83,12 +83,10 @@ BOOL SetOffline(MCONTACT hContact, BOOL) BOOL SetAllOffline(BOOL, const char *pszModule) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter(pszModule)) { char *szProto = GetContactProto(hContact); if (!chatApi.MM_FindModule(szProto)) continue; - if (pszModule && mir_strcmp(pszModule, szProto)) - continue; int i = db_get_b(hContact, szProto, "ChatRoom", 0); if (i != 0) { db_set_w(hContact, szProto, "ApparentMode", 0); @@ -225,7 +223,7 @@ BOOL AddEvent(MCONTACT hContact, HICON hIcon, MEVENT hEvent, int type, wchar_t* MCONTACT FindRoom(const char *pszModule, const wchar_t *pszRoom) { - for (MCONTACT hContact = db_find_first(pszModule); hContact; hContact = db_find_next(hContact, pszModule)) { + for (auto &hContact : contact_iter(pszModule)) { if (!db_get_b(hContact, pszModule, "ChatRoom", 0)) continue; diff --git a/src/mir_app/src/clc.cpp b/src/mir_app/src/clc.cpp index a7c8b06698..8ece944316 100644 --- a/src/mir_app/src/clc.cpp +++ b/src/mir_app/src/clc.cpp @@ -248,7 +248,7 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam DWORD hitFlags; int hit; - ClcData *dat = (ClcData *) GetWindowLongPtr(hwnd, 0); + ClcData *dat = (ClcData *)GetWindowLongPtr(hwnd, 0); if (uMsg >= CLM_FIRST && uMsg < CLM_LAST) return cli.pfnProcessExternalMessages(hwnd, dat, uMsg, wParam, lParam); @@ -406,7 +406,7 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam int eq; if (dbcws->value.type == DBVT_ASCIIZ) - eq = !mir_wstrcmp(szFullName, _A2T(dbcws->value.pszVal+1)); + eq = !mir_wstrcmp(szFullName, _A2T(dbcws->value.pszVal + 1)); else eq = !mir_wstrcmp(szFullName, ptrW(mir_utf8decodeW(dbcws->value.pszVal + 1))); @@ -722,7 +722,7 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam if (!dat->bFilterSearch) dat->szQuickSearch[0] = 0; hit = cli.pfnGetRowByIndex(dat, dat->selection, &contact, &group); - if (hit == -1) + if (hit == -1) return 0; if (changeGroupExpand == 1 && contact->type == CLCIT_CONTACT) { @@ -1043,7 +1043,7 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam case DROPTARGET_OUTSIDE: if (pt.x >= 0 && pt.x < clRect.right && ((pt.y < 0 && pt.y > -dat->dragAutoScrollHeight) - || (pt.y >= clRect.bottom && pt.y < clRect.bottom + dat->dragAutoScrollHeight))) { + || (pt.y >= clRect.bottom && pt.y < clRect.bottom + dat->dragAutoScrollHeight))) { if (!dat->dragAutoScrolling) { if (pt.y < 0) dat->dragAutoScrolling = -1; @@ -1172,7 +1172,7 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam cli.pfnInvalidateRect(hwnd, nullptr, FALSE); if (dat->selection != -1) cli.pfnEnsureVisible(hwnd, dat, dat->selection, 0); - + if (hitFlags & (CLCHT_ONITEMICON | CLCHT_ONITEMLABEL)) { UpdateWindow(hwnd); cli.pfnDoSelectionDefaultAction(hwnd, dat); @@ -1236,7 +1236,7 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam hit = cli.pfnGetRowByIndex(dat, dat->selection, &contact, nullptr); if (hit == -1) break; - + if (contact->type == CLCIT_CONTACT) if (Clist_MenuProcessCommand(LOWORD(wParam), MPCF_CONTACTMENU, contact->hContact)) break; diff --git a/src/mir_app/src/clcitems.cpp b/src/mir_app/src/clcitems.cpp index 268135e832..704ecf0ef0 100644 --- a/src/mir_app/src/clcitems.cpp +++ b/src/mir_app/src/clcitems.cpp @@ -105,7 +105,7 @@ ClcGroup* fnAddGroup(HWND hwnd, ClcData *dat, const wchar_t *szName, DWORD flags group->totalMembers = 0; if (flags != (DWORD)-1 && pNextField == nullptr && calcTotalMembers) { DWORD style = GetWindowLongPtr(hwnd, GWL_STYLE); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { ClcCacheEntry *cache = cli.pfnGetCacheEntry(hContact); if (!mir_wstrcmp(cache->tszGroup, szName) && (style & CLS_SHOWHIDDEN || !cache->bIsHidden)) group->totalMembers++; @@ -359,7 +359,7 @@ void fnRebuildEntireList(HWND hwnd, ClcData *dat) cli.pfnAddGroup(hwnd, dat, szGroupName, groupFlags, i, 0); } - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { int nHiddenStatus = cli.pfnGetContactHiddenStatus(hContact, nullptr, dat); if (((style & CLS_SHOWHIDDEN) && nHiddenStatus != -1) || !nHiddenStatus) { ClcCacheEntry *pce = cli.pfnGetCacheEntry(hContact); diff --git a/src/mir_app/src/clistgroups.cpp b/src/mir_app/src/clistgroups.cpp index 9dac871611..8527a131cc 100644 --- a/src/mir_app/src/clistgroups.cpp +++ b/src/mir_app/src/clistgroups.cpp @@ -203,7 +203,7 @@ MIR_APP_DLL(int) Clist_GroupDelete(MGROUP hGroup) szNewParent[0] = '\0'; } - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { ptrW tszGroupName(db_get_wsa(hContact, "CList", "Group")); if (mir_wstrcmp(tszGroupName, pGroup->groupName+1)) continue; @@ -342,7 +342,7 @@ static int RenameGroupWithMove(int groupId, const wchar_t *szName, int move) arByName.insert(pGroup); // must rename setting in all child contacts too - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { ClcCacheEntry *cache = cli.pfnGetCacheEntry(hContact); if (!mir_wstrcmp(cache->tszGroup, oldName)) { db_set_ws(hContact, "CList", "Group", szName); diff --git a/src/mir_app/src/contact.cpp b/src/mir_app/src/contact.cpp index f6b2a7e8ce..d365c01d83 100644 --- a/src/mir_app/src/contact.cpp +++ b/src/mir_app/src/contact.cpp @@ -38,7 +38,7 @@ static int GetContactStatus(MCONTACT hContact) void fnLoadContactTree(void) { int hideOffline = db_get_b(0, "CList", "HideOffline", SETTING_HIDEOFFLINE_DEFAULT); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { int status = GetContactStatus(hContact); if ((!hideOffline || status != ID_STATUS_OFFLINE) && !db_get_b(hContact, "CList", "Hidden", 0)) cli.pfnChangeContactIcon(hContact, cli.pfnIconFromStatusMode(GetContactProto(hContact), status, hContact)); diff --git a/src/mir_app/src/ignore.cpp b/src/mir_app/src/ignore.cpp index f0c9032a0a..7ee5f1ec7f 100644 --- a/src/mir_app/src/ignore.cpp +++ b/src/mir_app/src/ignore.cpp @@ -172,7 +172,7 @@ static void SaveItemMask(HWND hwndList, MCONTACT hContact, HANDLE hItem, const c static void SetAllContactIcons(HWND hwndList) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0); if (hItem && SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(IGNOREEVENT_MAX, 0)) == EMPTY_EXTRA_ICON) { DWORD proto1Caps, proto4Caps; @@ -297,7 +297,7 @@ static INT_PTR CALLBACK DlgProcIgnoreOpts(HWND hwndDlg, UINT msg, WPARAM, LPARAM case 0: switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_LIST, CLM_FINDCONTACT, hContact, 0); if (hItem) SaveItemMask(GetDlgItem(hwndDlg, IDC_LIST), hContact, hItem, "Mask1"); if (SendDlgItemMessage(hwndDlg, IDC_LIST, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) diff --git a/src/mir_app/src/meta_addto.cpp b/src/mir_app/src/meta_addto.cpp index d3c01aad3f..13adca2900 100644 --- a/src/mir_app/src/meta_addto.cpp +++ b/src/mir_app/src/meta_addto.cpp @@ -43,7 +43,7 @@ static int FillList(HWND list, BOOL sort) int i = 0; // The DB is searched through, to get all the metacontacts - for (MCONTACT hMetaUser = db_find_first(); hMetaUser; hMetaUser = db_find_next(hMetaUser)) { + for (auto &hMetaUser : contact_iter()) { // if it's not a MetaContact, go to the next DBCachedContact *cc = CheckMeta(hMetaUser); if (cc == nullptr) diff --git a/src/mir_app/src/meta_main.cpp b/src/mir_app/src/meta_main.cpp index 9689ba3c93..c8d8824c87 100644 --- a/src/mir_app/src/meta_main.cpp +++ b/src/mir_app/src/meta_main.cpp @@ -77,7 +77,7 @@ int LoadMetacontacts(void) db_set_resident(META_PROTO, "IdleTS"); // set all contacts to 'offline', and initialize subcontact counter for db consistency check - for (MCONTACT hContact = db_find_first(META_PROTO); hContact; hContact = db_find_next(hContact, META_PROTO)) { + for (auto &hContact : contact_iter(META_PROTO)) { db_set_w(hContact, META_PROTO, "Status", ID_STATUS_OFFLINE); db_set_dw(hContact, META_PROTO, "IdleTS", 0); } diff --git a/src/mir_app/src/meta_utils.cpp b/src/mir_app/src/meta_utils.cpp index 1ebeb71319..2c85284f71 100644 --- a/src/mir_app/src/meta_utils.cpp +++ b/src/mir_app/src/meta_utils.cpp @@ -321,7 +321,7 @@ int Meta_HideLinkedContacts(void) DBVARIANT dbv, dbv2; char buffer[512]; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { DBCachedContact *cc = currDb->m_cache->GetCachedContact(hContact); if (cc == nullptr || cc->parentID == 0) continue; @@ -385,7 +385,7 @@ int Meta_HideMetaContacts(bool bHide) // set status suppression bool bSuppress = bHide ? FALSE : g_metaOptions.bSuppressStatus; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { bool bSet; DBCachedContact *cc = currDb->m_cache->GetCachedContact(hContact); if (cc->IsSub()) { // show on hide, reverse flag @@ -411,7 +411,7 @@ int Meta_HideMetaContacts(bool bHide) int Meta_SuppressStatus(bool suppress) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) if (db_mc_isSub(hContact)) CallService((suppress) ? MS_IGNORE_IGNORE : MS_IGNORE_UNIGNORE, hContact, IGNOREEVENT_USERONLINE); @@ -449,7 +449,7 @@ int Meta_CopyContactNick(DBCachedContact *ccMeta, MCONTACT hContact) int Meta_SetAllNicks() { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { DBCachedContact *cc = CheckMeta(hContact); if (cc == nullptr) continue; diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index a65d30b6a8..8decb6d44b 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -488,3 +488,4 @@ Image_LoadFromMem @505 Image_Resize @506 Image_Save @507 GetDatabasePlugin @508 +?acc_contact_iter@PROTO_INTERFACE@@QBE?AVcontact_iter@@XZ @509 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 2a29d7d486..b09d9d1218 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -488,3 +488,4 @@ Image_LoadFromMem @505 Image_Resize @506 Image_Save @507 GetDatabasePlugin @508 +?acc_contact_iter@PROTO_INTERFACE@@QEBA?AVcontact_iter@@XZ @509 NONAME diff --git a/src/mir_app/src/options_ei.cpp b/src/mir_app/src/options_ei.cpp index 9ac0e0bad4..006272ad62 100644 --- a/src/mir_app/src/options_ei.cpp +++ b/src/mir_app/src/options_ei.cpp @@ -77,7 +77,7 @@ BOOL ScreenToClient(HWND hWnd, LPRECT lpRect) static void RemoveExtraIcons(int slot) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) Clist_SetExtraIcon(hContact, slot, INVALID_HANDLE_VALUE); } diff --git a/src/mir_app/src/proto_utils.cpp b/src/mir_app/src/proto_utils.cpp index 586b9f330d..e86454b858 100644 --- a/src/mir_app/src/proto_utils.cpp +++ b/src/mir_app/src/proto_utils.cpp @@ -64,7 +64,7 @@ MIR_APP_DLL(INT_PTR) ProtoBroadcastAck(const char *szModule, MCONTACT hContact, void PROTO_INTERFACE::setAllContactStatuses(int iStatus, bool bSkipChats) { - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (isChatRoom(hContact)) { if (!bSkipChats && iStatus == ID_STATUS_OFFLINE) { ptrW wszRoom(getWStringA(hContact, "ChatRoomID")); diff --git a/src/mir_app/src/visibility.cpp b/src/mir_app/src/visibility.cpp index 5946ca3159..e3c13a1c34 100644 --- a/src/mir_app/src/visibility.cpp +++ b/src/mir_app/src/visibility.cpp @@ -100,7 +100,7 @@ static void ResetListOptions(HWND hwndList) static void SetAllContactIcons(HWND hwndList) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0); if (hItem == nullptr) continue; @@ -235,7 +235,7 @@ static INT_PTR CALLBACK DlgProcVisibilityOpts(HWND hwndDlg, UINT msg, WPARAM, LP case 0: if (((LPNMHDR)lParam)->code == PSN_APPLY) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_LIST, CLM_FINDCONTACT, hContact, 0); if (hItem == nullptr) continue; -- cgit v1.2.3