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 --- protocols/Gadu-Gadu/src/core.cpp | 8 ++++---- protocols/Gadu-Gadu/src/groupchat.cpp | 6 +++--- protocols/Gadu-Gadu/src/import.cpp | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'protocols/Gadu-Gadu') diff --git a/protocols/Gadu-Gadu/src/core.cpp b/protocols/Gadu-Gadu/src/core.cpp index 266ff97786..f34163ad81 100644 --- a/protocols/Gadu-Gadu/src/core.cpp +++ b/protocols/Gadu-Gadu/src/core.cpp @@ -1373,7 +1373,7 @@ void GaduProto::setalloffline() debugLogA("setalloffline(): started. Setting buddies offline"); setWord(GG_KEY_STATUS, ID_STATUS_OFFLINE); - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { setWord(hContact, GG_KEY_STATUS, ID_STATUS_OFFLINE); // Clear IP and port settings delSetting(hContact, GG_KEY_CLIENTIP); @@ -1437,7 +1437,7 @@ void GaduProto::notifyall() debugLogA("notifyall(): Subscribing notification to all users"); // Readup count int count = 0; - for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) + for (auto &hContact : acc_contact_iter()) count++; // Readup list @@ -1454,7 +1454,7 @@ void GaduProto::notifyall() char *types = (char*)calloc(sizeof(char), count); int cc = 0; - for (hContact = db_find_first(m_szModuleName); hContact && cc < count; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (uins[cc] = getDword(hContact, GG_KEY_UIN, 0)) { if ((getWord(hContact, GG_KEY_APPARENT, (WORD)ID_STATUS_ONLINE) == ID_STATUS_OFFLINE) || db_get_b(hContact, "CList", "NotOnList", 0)) @@ -1490,7 +1490,7 @@ MCONTACT GaduProto::getcontact(uin_t uin, int create, int inlist, wchar_t *szNic debugLogA("getcontact(): uin=%d create=%d inlist=%d", uin, create, inlist); #endif // Look for contact in DB - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if ((uin_t)getDword(hContact, GG_KEY_UIN, 0) == uin && !isChatRoom(hContact)) { if (inlist) { db_unset(hContact, "CList", "NotOnList"); diff --git a/protocols/Gadu-Gadu/src/groupchat.cpp b/protocols/Gadu-Gadu/src/groupchat.cpp index 2126cfdb53..7e6d7a823f 100644 --- a/protocols/Gadu-Gadu/src/groupchat.cpp +++ b/protocols/Gadu-Gadu/src/groupchat.cpp @@ -407,7 +407,7 @@ static void gg_gc_resetclistopts(HWND hwndList) static int gg_gc_countcheckmarks(HWND hwndList) { int count = 0; - 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_GETCHECKMARK, (WPARAM)hItem, 0)) ++count; @@ -459,7 +459,7 @@ static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wPa // Create new participiants table uin_t* participants = (uin_t*)calloc(count, sizeof(uin_t)); gg->debugLogA("gg_gc_openconfdlg(): WM_COMMAND IDOK Opening new conference for %d contacts.", count); - for (MCONTACT hContact = db_find_first(); hContact && i < count; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0); if (hItem && SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) { MCONTACT hMetaContact = gg_getsubcontact(gg, hContact); // MetaContacts support @@ -508,7 +508,7 @@ static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wPa break; // Delete non-gg contacts - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { MCONTACT hItem = (MCONTACT)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem) { MCONTACT hMetaContact = gg_getsubcontact(gg, hContact); // MetaContacts support diff --git a/protocols/Gadu-Gadu/src/import.cpp b/protocols/Gadu-Gadu/src/import.cpp index 23c621ead5..ae8c96764f 100644 --- a/protocols/Gadu-Gadu/src/import.cpp +++ b/protocols/Gadu-Gadu/src/import.cpp @@ -25,7 +25,7 @@ char *gg_makecontacts(GaduProto *gg, int cr) string_t s = string_init(nullptr); // Readup contacts - for (MCONTACT hContact = db_find_first(gg->m_szModuleName); hContact; hContact = db_find_next(hContact, gg->m_szModuleName)) { + for (auto &hContact : gg->acc_contact_iter()) { if (gg->isChatRoom(hContact)) continue; -- cgit v1.2.3