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 --- plugins/AVS/src/options.cpp | 2 +- plugins/AuthState/src/main.cpp | 2 +- plugins/AuthState/src/options.h | 2 +- plugins/AutoShutdown/src/watcher.cpp | 2 +- plugins/BasicHistory/src/HistoryWindow.cpp | 22 +- plugins/BasicHistory/src/Options.cpp | 8 +- plugins/BuddyExpectator/src/BuddyExpectator.cpp | 4 +- plugins/BuddyExpectator/src/options.cpp | 2 +- plugins/BuddyPounce/src/dialog.cpp | 2 +- plugins/Clist_modern/src/modern_viewmodebar.cpp | 8 +- plugins/Clist_nicer/src/contact.cpp | 4 +- plugins/Clist_nicer/src/extBackg.cpp | 2 +- plugins/Clist_nicer/src/viewmodes.cpp | 8 +- plugins/CloudFile/src/events.cpp | 2 +- plugins/CmdLine/src/mimcmd_handlers.cpp | 8 +- plugins/CmdLine/src/utils.cpp | 2 +- plugins/ConnectionNotify/src/ConnectionNotify.cpp | 2 +- plugins/ContactsPlus/src/main.cpp | 2 +- plugins/CountryFlags/src/extraimg.cpp | 8 +- plugins/DbEditorPP/src/copymodule.cpp | 4 +- plugins/DbEditorPP/src/deletemodule.cpp | 5 +- plugins/DbEditorPP/src/exportimport.cpp | 3 +- plugins/DbEditorPP/src/findwindow.cpp | 3 +- plugins/DbEditorPP/src/modsettingenum.cpp | 2 +- plugins/DbEditorPP/src/moduletree.cpp | 6 +- plugins/DbEditorPP/src/renamemodule.cpp | 2 +- plugins/FavContacts/src/contact_cache.cpp | 2 +- plugins/FavContacts/src/favlist.h | 2 +- plugins/FavContacts/src/options.cpp | 8 +- plugins/FavContacts/src/services.cpp | 2 +- plugins/FingerprintNG/src/options.cpp | 2 +- plugins/FloatingContacts/src/main.cpp | 2 +- plugins/GmailNotifier/src/utility.cpp | 2 +- plugins/HistoryStats/src/dlgoption_subexclude.cpp | 10 +- plugins/HistoryStats/src/mirandahistory.cpp | 2 +- .../src/historysweeperlight.cpp | 2 +- plugins/HistorySweeperLight/src/options.cpp | 4 +- plugins/IgnoreState/src/main.cpp | 2 +- plugins/KeyboardNotify/src/ignore.cpp | 4 +- plugins/ListeningTo/src/listeningto.cpp | 2 +- plugins/ListeningTo/src/players/mradio.cpp | 2 +- plugins/LotusNotify/src/LotusNotify.cpp | 2 +- plugins/MessageState/src/messagestate.cpp | 2 +- plugins/MirFox/src/MirandaOptions.cpp | 2 +- plugins/MirFox/src/MirandaUtils.cpp | 2 +- plugins/MirFox/src/MirfoxData.cpp | 2 +- plugins/MirOTR/src/dllmain.cpp | 2 +- plugins/MirOTR/src/options.cpp | 2 +- plugins/MirOTR/src/utils.cpp | 2 +- plugins/MirandaG15/src/CContactList.cpp | 734 ++++++++++----------- plugins/MobileState/src/main.cpp | 2 +- plugins/Msg_Export/src/options.cpp | 2 +- plugins/Msg_Export/src/utils.cpp | 4 +- plugins/NewAwaySysMod/src/AwayOpt.cpp | 12 +- plugins/NewAwaySysMod/src/AwaySys.cpp | 2 +- plugins/NewAwaySysMod/src/Properties.cpp | 7 +- plugins/NewAwaySysMod/src/SetAwayMsg.cpp | 4 +- plugins/NewXstatusNotify/src/indsnd.cpp | 4 +- plugins/New_GPG/src/icons.cpp | 2 +- plugins/New_GPG/src/options.cpp | 8 +- plugins/New_GPG/src/utilities.cpp | 4 +- plugins/NewsAggregator/Src/Options.cpp | 10 +- plugins/NewsAggregator/Src/Services.cpp | 6 +- plugins/NewsAggregator/Src/Update.cpp | 2 +- plugins/NewsAggregator/Src/Utils.cpp | 4 +- plugins/NoHistory/src/options.cpp | 4 +- plugins/Non-IM Contact/src/files.cpp | 2 +- plugins/Non-IM Contact/src/services.cpp | 2 +- plugins/Non-IM Contact/src/timer.cpp | 2 +- plugins/Popup/src/opt_contacts.cpp | 4 +- plugins/QuickContacts/src/quickcontacts.cpp | 2 +- plugins/Quotes/src/ImportExport.cpp | 2 +- plugins/Quotes/src/QuotesProviders.cpp | 2 +- plugins/Rate/src/main.cpp | 2 +- plugins/RecentContacts/src/RecentContacts.cpp | 2 +- plugins/SMS/src/SMS_svc.cpp | 2 +- plugins/SMS/src/functions.cpp | 2 +- plugins/SMS/src/senddlg.cpp | 2 +- plugins/Scriver/src/msgoptions.cpp | 4 +- plugins/Scriver/src/msgs.cpp | 2 +- plugins/SecureIM/src/crypt_icons.cpp | 2 +- plugins/SecureIM/src/crypt_lists.cpp | 2 +- plugins/SecureIM/src/options.cpp | 8 +- plugins/SeenPlugin/src/missed.cpp | 4 +- plugins/SeenPlugin/src/utils.cpp | 2 +- plugins/Sessions/Src/Main.cpp | 12 +- plugins/Sessions/Src/Options.cpp | 6 +- plugins/ShellExt/src/shlcom.cpp | 4 +- plugins/SimpleStatusMsg/src/main.cpp | 2 +- plugins/SmileyAdd/src/smileys.cpp | 4 +- plugins/Spamotron/src/spamotron.cpp | 4 +- plugins/StopSpamMod/src/utilities.cpp | 4 +- plugins/TabSRMM/src/container.cpp | 4 +- plugins/TabSRMM/src/globals.cpp | 4 +- plugins/TabSRMM/src/msgoptions.cpp | 4 +- plugins/TabSRMM/src/sendqueue.cpp | 4 +- plugins/TabSRMM/src/trayicon.cpp | 2 +- plugins/TipperYM/src/options.cpp | 4 +- plugins/TipperYM/src/popwin.cpp | 4 +- plugins/TooltipNotify/src/TooltipNotify.cpp | 4 +- plugins/UserInfoEx/src/dlg_anniversarylist.cpp | 2 +- plugins/UserInfoEx/src/dlg_propsheet.cpp | 3 +- .../src/ex_import/classExImContactBase.cpp | 2 +- plugins/UserInfoEx/src/psp_options.cpp | 4 +- plugins/UserInfoEx/src/svc_avatar.cpp | 4 +- plugins/UserInfoEx/src/svc_refreshci.cpp | 2 +- plugins/UserInfoEx/src/svc_reminder.cpp | 6 +- plugins/Variables/src/contact.cpp | 2 +- plugins/Variables/src/parse_miranda.cpp | 8 +- plugins/Weather/src/weather_addstn.cpp | 2 +- plugins/Weather/src/weather_contacts.cpp | 2 +- plugins/Weather/src/weather_data.cpp | 2 +- plugins/Weather/src/weather_mwin.cpp | 4 +- plugins/Weather/src/weather_update.cpp | 2 +- plugins/WebView/src/main.cpp | 2 +- plugins/WebView/src/webview.cpp | 8 +- plugins/WebView/src/webview_datawnd.cpp | 2 +- plugins/WebView/src/webview_services.cpp | 11 +- plugins/WhenWasIt/src/dlg_handlers.cpp | 2 +- plugins/WhenWasIt/src/notifiers.cpp | 2 +- plugins/WhenWasIt/src/services.cpp | 2 +- plugins/WhenWasIt/src/utils.cpp | 2 +- plugins/WinterSpeak/src/ConfigDatabase.cpp | 5 +- plugins/WinterSpeak/src/DialogConfigActive.cpp | 2 +- plugins/XSoundNotify/src/options.cpp | 2 +- plugins/YAMN/src/proto/pop3/pop3comm.cpp | 2 +- plugins/YAPP/src/options.cpp | 2 +- plugins/YARelay/src/options.cpp | 3 +- 128 files changed, 562 insertions(+), 638 deletions(-) (limited to 'plugins') diff --git a/plugins/AVS/src/options.cpp b/plugins/AVS/src/options.cpp index 22468bc948..7940a80475 100644 --- a/plugins/AVS/src/options.cpp +++ b/plugins/AVS/src/options.cpp @@ -406,7 +406,7 @@ static INT_PTR CALLBACK DlgProcOptionsProtos(HWND hwndDlg, UINT msg, WPARAM wPar BOOL newVal = ListView_GetCheckState(hwndList, i); if (oldVal && !newVal) - for (MCONTACT hContact = db_find_first(szProto); hContact; hContact = db_find_next(hContact, szProto)) + for (auto &hContact : contact_iter(szProto)) DeleteAvatarFromCache(hContact, TRUE); if (newVal) diff --git a/plugins/AuthState/src/main.cpp b/plugins/AuthState/src/main.cpp index 25f3810ac0..cefe05a0be 100644 --- a/plugins/AuthState/src/main.cpp +++ b/plugins/AuthState/src/main.cpp @@ -157,7 +157,7 @@ int onModulesLoaded(WPARAM, LPARAM) hExtraIcon = ExtraIcon_RegisterIcolib("authstate", LPGEN("Auth state"), iconList[ICON_BOTH].szName); // Set initial value for all contacts - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) onExtraImageApplying((WPARAM)hContact, 1); HookEvent(ME_OPT_INITIALISE, onOptInitialise); diff --git a/plugins/AuthState/src/options.h b/plugins/AuthState/src/options.h index 7a3b426615..1f105b6dfb 100644 --- a/plugins/AuthState/src/options.h +++ b/plugins/AuthState/src/options.h @@ -40,7 +40,7 @@ public: void OnApply() override { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) onExtraImageApplying((WPARAM)hContact, 0); } diff --git a/plugins/AutoShutdown/src/watcher.cpp b/plugins/AutoShutdown/src/watcher.cpp index 04f8429eb0..768f85bb74 100644 --- a/plugins/AutoShutdown/src/watcher.cpp +++ b/plugins/AutoShutdown/src/watcher.cpp @@ -176,7 +176,7 @@ static BOOL CheckAllContactsOffline(void) { BOOL fSmartCheck, fAllOffline = TRUE; /* tentatively */ fSmartCheck = db_get_b(NULL, "AutoShutdown", "SmartOfflineCheck", SETTING_SMARTOFFLINECHECK_DEFAULT); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { char *pszProto = GetContactProto(hContact); if (pszProto != nullptr && CallProtoService(pszProto, PS_GETSTATUS, 0, 0) != ID_STATUS_OFFLINE) { if (db_get_b(hContact, pszProto, "ChatRoom", 0)) continue; diff --git a/plugins/BasicHistory/src/HistoryWindow.cpp b/plugins/BasicHistory/src/HistoryWindow.cpp index 4f035f5255..88f20deb9f 100644 --- a/plugins/BasicHistory/src/HistoryWindow.cpp +++ b/plugins/BasicHistory/src/HistoryWindow.cpp @@ -1496,7 +1496,7 @@ void HistoryWindow::ReloadContacts() } } - for (MCONTACT _hContact = db_find_first(); _hContact; _hContact = db_find_next(_hContact)) { + for (auto &_hContact : contact_iter()) { if (HistoryEventList::GetContactMessageNumber(_hContact) && (metaContactProto == nullptr || !db_mc_isSub(_hContact))) { HANDLE hItem = (HANDLE)SendMessage(contactList, CLM_FINDCONTACT, (WPARAM)_hContact, 0); if (hItem == nullptr) @@ -1627,7 +1627,7 @@ void HistoryWindow::SavePos(bool all) { MCONTACT contactToSave = m_hContact; if (all) { - for (MCONTACT _hContact = db_find_first(); _hContact; _hContact = db_find_next(_hContact)) { + for (auto &_hContact : contact_iter()) { db_unset(_hContact, MODULE, "history_x"); db_unset(_hContact, MODULE, "history_y"); db_unset(_hContact, MODULE, "history_width"); @@ -1825,7 +1825,7 @@ void HistoryWindow::DoImport(IImport::ImportType type) std::wstring err; std::vector contacts; - for (MCONTACT _hContact = db_find_first(); _hContact != NULL; _hContact = db_find_next(_hContact)) + for (auto &_hContact : contact_iter()) contacts.push_back(_hContact); bool changeContact = false; @@ -2049,7 +2049,7 @@ MCONTACT HistoryWindow::GetNextContact(MCONTACT hContact, int adder) HWND contactList = GetDlgItem(m_hWnd, IDC_LIST_CONTACTS); if (adder > 0) { if (hContact != NULL) { - for (MCONTACT cc = db_find_next(hContact); cc; cc = db_find_next(cc)) + for (auto &cc : contact_iter()) if (SendMessage(contactList, CLM_FINDCONTACT, cc, 0) != NULL) return cc; @@ -2057,19 +2057,27 @@ MCONTACT HistoryWindow::GetNextContact(MCONTACT hContact, int adder) return NULL; } - for (MCONTACT cc = db_find_first(); cc && cc != hContact; cc = db_find_next(cc)) + for (auto &cc : contact_iter()) { + if (cc == hContact) + break; + if (SendMessage(contactList, CLM_FINDCONTACT, cc, 0) != NULL) return cc; + } } else { MCONTACT lastContact = NULL; - for (MCONTACT cc = db_find_first(); cc && cc != hContact; cc = db_find_next(cc)) + for (auto &cc : contact_iter()) { + if (cc == hContact) + break; + if (SendMessage(contactList, CLM_FINDCONTACT, cc, 0) != NULL) lastContact = cc; + } if (hContact != NULL) { if (lastContact == NULL && !HistoryEventList::GetContactMessageNumber(NULL)) { - for (MCONTACT cc = db_find_next(hContact); cc; cc = db_find_next(cc)) + for (auto &cc : contact_iter()) if (SendMessage(contactList, CLM_FINDCONTACT, cc, 0) != NULL) lastContact = cc; } diff --git a/plugins/BasicHistory/src/Options.cpp b/plugins/BasicHistory/src/Options.cpp index 6df06b59b0..b86a6cc91f 100644 --- a/plugins/BasicHistory/src/Options.cpp +++ b/plugins/BasicHistory/src/Options.cpp @@ -550,7 +550,7 @@ void Options::SaveTasks(std::list* tasks) db_set_s(0, MODULE, buf, it->zipPassword.c_str()); mir_snprintf(buf, "IsInTask_%d", i); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) db_unset(hContact, MODULE, buf); for (size_t j = 0; j < it->contacts.size(); ++j) @@ -605,7 +605,7 @@ void Options::SaveTasks(std::list* tasks) db_unset(NULL, MODULE, buf); mir_snprintf(buf, "IsInTask_%d", i); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) db_unset(hContact, MODULE, buf); } } @@ -691,7 +691,7 @@ void Options::LoadTasks() } mir_snprintf(buf, "IsInTask_%d", i); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) if (db_get_b(hContact, MODULE, buf, 0) == 1) to.contacts.push_back(hContact); @@ -1562,7 +1562,7 @@ void SaveList(HWND hwnd, MCONTACT hSystem, TaskOptions* to) if (hSystem) to->isSystem = SendMessage(hwnd, CLM_GETCHECKMARK, (WPARAM)hSystem, 0) != 0; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendMessage(hwnd, CLM_FINDCONTACT, hContact, 0); if (hItem && SendMessage(hwnd, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) to->contacts.push_back(hContact); diff --git a/plugins/BuddyExpectator/src/BuddyExpectator.cpp b/plugins/BuddyExpectator/src/BuddyExpectator.cpp index 00dbf156fe..231386b321 100644 --- a/plugins/BuddyExpectator/src/BuddyExpectator.cpp +++ b/plugins/BuddyExpectator/src/BuddyExpectator.cpp @@ -542,7 +542,7 @@ int SettingChanged(WPARAM hContact, LPARAM lParam) void CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { char *proto = GetContactProto(hContact); if (proto && (db_get_b(hContact, proto, "ChatRoom", 0) == 0) && (CallProtoService(proto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IMSEND) && isContactGoneFor(hContact, options.iAbsencePeriod2) && (db_get_b(hContact, MODULE_NAME, "StillAbsentNotified", 0) == 0)) { @@ -672,7 +672,7 @@ extern "C" int __declspec(dllexport) Load(void) DBVARIANT dbv; DWORD current_time = (DWORD)time(nullptr); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { if (!db_get(hContact, MODULE_NAME, "CreationTime", &dbv)) db_free(&dbv); else diff --git a/plugins/BuddyExpectator/src/options.cpp b/plugins/BuddyExpectator/src/options.cpp index d431c5af96..db6c577176 100644 --- a/plugins/BuddyExpectator/src/options.cpp +++ b/plugins/BuddyExpectator/src/options.cpp @@ -246,7 +246,7 @@ static INT_PTR CALLBACK OptionsFrameProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, SaveOptions(); // clear all notified settings - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) if (db_get_b(hContact, MODULE_NAME, "StillAbsentNotified", 0)) db_set_b(hContact, MODULE_NAME, "StillAbsentNotified", 0); diff --git a/plugins/BuddyPounce/src/dialog.cpp b/plugins/BuddyPounce/src/dialog.cpp index 024d51f8ad..237204e886 100644 --- a/plugins/BuddyPounce/src/dialog.cpp +++ b/plugins/BuddyPounce/src/dialog.cpp @@ -12,7 +12,7 @@ void populateSettingsList(HWND hwnd2List) void populateContacts(MCONTACT BPhContact, HWND hwnd2CB) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { char *szProto = GetContactProto(hContact); if (szProto && (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IM)) { wchar_t name[300]; diff --git a/plugins/Clist_modern/src/modern_viewmodebar.cpp b/plugins/Clist_modern/src/modern_viewmodebar.cpp index 9c50528e0d..3c9ea70dc1 100644 --- a/plugins/Clist_modern/src/modern_viewmodebar.cpp +++ b/plugins/Clist_modern/src/modern_viewmodebar.cpp @@ -174,7 +174,7 @@ static DWORD GetMaskForItem(HANDLE hItem) static void UpdateStickies() { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { MCONTACT hItem = (MCONTACT)SendDlgItemMessage(clvmHwnd, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem) SendDlgItemMessage(clvmHwnd, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM)hItem, (BYTE)db_get_dw(hContact, CLVM_MODULE, g_szModename, 0) ? 1 : 0); @@ -432,7 +432,7 @@ void SaveState() T2Utf szModeName(szTempModeName); DWORD dwGlobalMask = GetMaskForItem(hInfoItem); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendDlgItemMessage(clvmHwnd, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem == nullptr) continue; @@ -624,7 +624,7 @@ void DeleteViewMode(char * szName) SetWindowText(hwndSelector, TranslateT("All contacts")); } - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) if (db_get_dw(hContact, CLVM_MODULE, szName, -1) != -1) db_set_dw(hContact, CLVM_MODULE, szName, 0); } @@ -793,7 +793,7 @@ INT_PTR CALLBACK DlgProcViewModesSetup(HWND hwndDlg, UINT msg, WPARAM wParam, LP } case IDC_CLEARALL: { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem) SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM)hItem, 0); diff --git a/plugins/Clist_nicer/src/contact.cpp b/plugins/Clist_nicer/src/contact.cpp index facb3a48a6..f62749c3eb 100644 --- a/plugins/Clist_nicer/src/contact.cpp +++ b/plugins/Clist_nicer/src/contact.cpp @@ -113,7 +113,7 @@ void MF_UpdateThread(LPVOID) ResetEvent(hEvent); while (mf_updatethread_running) { - for (MCONTACT hContact = db_find_first(); hContact && mf_updatethread_running; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { MF_CalcFrequency(hContact, 50, 1); if (mf_updatethread_running) WaitForSingleObject(hEvent, 5000); @@ -130,7 +130,7 @@ void MF_InitCheck(void) { BYTE bMsgFrequency = db_get_b(NULL, "CList", "fhistdata", 0); if (!bMsgFrequency) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) MF_CalcFrequency(hContact, 100, 0); db_set_b(NULL, "CList", "fhistdata", 1); } diff --git a/plugins/Clist_nicer/src/extBackg.cpp b/plugins/Clist_nicer/src/extBackg.cpp index 8a6229c1ba..815a4e3e95 100644 --- a/plugins/Clist_nicer/src/extBackg.cpp +++ b/plugins/Clist_nicer/src/extBackg.cpp @@ -1281,7 +1281,7 @@ void LoadPerContactSkins(wchar_t *tszFileName) } if (items) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { char *szProto = GetContactProto(hContact); if (szProto == nullptr) continue; diff --git a/plugins/Clist_nicer/src/viewmodes.cpp b/plugins/Clist_nicer/src/viewmodes.cpp index 61c058a65d..01c19789a5 100644 --- a/plugins/Clist_nicer/src/viewmodes.cpp +++ b/plugins/Clist_nicer/src/viewmodes.cpp @@ -134,7 +134,7 @@ static DWORD GetMaskForItem(HANDLE hItem) static void UpdateStickies() { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { MCONTACT hItem = (MCONTACT)SendDlgItemMessage(sttClvmHwnd, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem) SendDlgItemMessage(sttClvmHwnd, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM)hItem, db_get_b(hContact, "CLVM", sttModeName, 0) ? 1 : 0); @@ -374,7 +374,7 @@ void SaveState() DWORD dwGlobalMask = GetMaskForItem(hInfoItem); unsigned int stickies = 0; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendDlgItemMessage(sttClvmHwnd, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem) { if (SendDlgItemMessage(sttClvmHwnd, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) { @@ -652,7 +652,7 @@ INT_PTR CALLBACK DlgProcViewModesSetup(HWND hwndDlg, UINT msg, WPARAM wParam, LP Clist_Broadcast(CLM_AUTOREBUILD, 0, 0); SetWindowText(hwndSelector, TranslateT("No view mode")); } - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) if (db_get_dw(hContact, "CLVM", szBuf, -1) != -1) db_set_dw(hContact, "CLVM", szBuf, 0); @@ -695,7 +695,7 @@ INT_PTR CALLBACK DlgProcViewModesSetup(HWND hwndDlg, UINT msg, WPARAM wParam, LP break; case IDC_CLEARALL: - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem) SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM)hItem, 0); diff --git a/plugins/CloudFile/src/events.cpp b/plugins/CloudFile/src/events.cpp index 869413978c..874ce16f72 100644 --- a/plugins/CloudFile/src/events.cpp +++ b/plugins/CloudFile/src/events.cpp @@ -7,7 +7,7 @@ static int OnProtoAck(WPARAM, LPARAM lParam) if (ack->type != ACKTYPE_STATUS) return 0; - for (MCONTACT hContact = db_find_first(ack->szModule); hContact; hContact = db_find_next(hContact, ack->szModule)) { + for (auto &hContact : contact_iter(ack->szModule)) { MessageWindowData msgw; if (Srmm_GetWindowData(hContact, msgw) || !(msgw.uState & MSG_WINDOW_STATE_EXISTS)) continue; diff --git a/plugins/CmdLine/src/mimcmd_handlers.cpp b/plugins/CmdLine/src/mimcmd_handlers.cpp index ad5a1cb216..122f7bfedd 100644 --- a/plugins/CmdLine/src/mimcmd_handlers.cpp +++ b/plugins/CmdLine/src/mimcmd_handlers.cpp @@ -1227,7 +1227,7 @@ void HandleContactsCommand(PCommand command, TArgument *argv, int argc, PReply r int count = 0; reply->code = MIMRES_SUCCESS; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { GetContactProto(hContact, protocol, _countof(protocol)); ptrW contact(GetContactName(hContact, protocol)); @@ -1257,7 +1257,7 @@ void HandleContactsCommand(PCommand command, TArgument *argv, int argc, PReply r reply->code = MIMRES_SUCCESS; *reply->message = 0; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { GetContactProto(hContact, protocol, _countof(protocol)); ptrW contact(GetContactName(hContact, protocol)); @@ -1270,7 +1270,7 @@ void HandleContactsCommand(PCommand command, TArgument *argv, int argc, PReply r reply->code = MIMRES_SUCCESS; *reply->message = 0; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { MEVENT hUnreadEvent = db_event_firstUnread(hContact); if (hUnreadEvent != NULL) mir_forkthread(OpenMessageWindowThread, (void*)hContact); @@ -1324,7 +1324,7 @@ void HandleHistoryCommand(PCommand command, TArgument *argv, int argc, PReply re reply->code = MIMRES_SUCCESS; mir_snwprintf(reply->message, TranslateT("No unread messages found.")); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { MEVENT hEvent = db_event_firstUnread(hContact); if (hEvent != NULL) { count = 0; diff --git a/plugins/CmdLine/src/utils.cpp b/plugins/CmdLine/src/utils.cpp index 97c2ef57f7..a7298887c6 100644 --- a/plugins/CmdLine/src/utils.cpp +++ b/plugins/CmdLine/src/utils.cpp @@ -171,7 +171,7 @@ MCONTACT GetContactFromID(wchar_t *szID, char *szProto) char cProtocol[256]; int found = 0; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { GetContactProto(hContact, cProtocol, sizeof(cProtocol)); ptrW szHandle(GetContactID(hContact, cProtocol)); diff --git a/plugins/ConnectionNotify/src/ConnectionNotify.cpp b/plugins/ConnectionNotify/src/ConnectionNotify.cpp index c0b09a621a..498891c076 100644 --- a/plugins/ConnectionNotify/src/ConnectionNotify.cpp +++ b/plugins/ConnectionNotify/src/ConnectionNotify.cpp @@ -866,7 +866,7 @@ extern "C" int __declspec(dllexport) Load(void) Proto_RegisterModule(&pd); //set all contacts to offline - for (MCONTACT hContact = db_find_first(PLUGINNAME); hContact != NULL; hContact = db_find_next(hContact, PLUGINNAME)) + for (auto &hContact : contact_iter(PLUGINNAME)) db_set_w(hContact, PLUGINNAME, "status", ID_STATUS_OFFLINE); CreateProtoServiceFunction(PLUGINNAME, PS_GETCAPS, GetCaps); diff --git a/plugins/ContactsPlus/src/main.cpp b/plugins/ContactsPlus/src/main.cpp index fed2bd4394..c78cf1698e 100644 --- a/plugins/ContactsPlus/src/main.cpp +++ b/plugins/ContactsPlus/src/main.cpp @@ -89,7 +89,7 @@ static int HookDBEventAdded(WPARAM hContact, LPARAM hDbEvent) static void ProcessUnreadEvents(void) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { for (MEVENT hDbEvent = db_event_firstUnread(hContact); hDbEvent; hDbEvent = db_event_next(hContact, hDbEvent)) { DBEVENTINFO dbei = {}; db_event_get(hDbEvent, &dbei); diff --git a/plugins/CountryFlags/src/extraimg.cpp b/plugins/CountryFlags/src/extraimg.cpp index cd2d31a485..d12ebf746b 100644 --- a/plugins/CountryFlags/src/extraimg.cpp +++ b/plugins/CountryFlags/src/extraimg.cpp @@ -63,14 +63,14 @@ static void CALLBACK SetExtraImage(MCONTACT hContact) // always call in context of main thread static void RemoveExtraImages(void) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) ExtraIcon_Clear(hExtraIcon, hContact); } // always call in context of main thread static void EnsureExtraImages(void) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) SetExtraImage(hContact); } @@ -135,8 +135,7 @@ static int MsgWndEvent(WPARAM, LPARAM lParam) void CALLBACK UpdateStatusIcons(LPARAM) { - MCONTACT hContact = db_find_first(); - while (hContact != NULL) { + for (auto &hContact : contact_iter()) { /* is a message window opened for this contact? */ MessageWindowData msgw; /* output */ if (!Srmm_GetWindowData(hContact, msgw) && msgw.uState & MSG_WINDOW_STATE_EXISTS) { @@ -146,7 +145,6 @@ void CALLBACK UpdateStatusIcons(LPARAM) } else UnsetStatusIcon(hContact); } - hContact = db_find_next(hContact); } } diff --git a/plugins/DbEditorPP/src/copymodule.cpp b/plugins/DbEditorPP/src/copymodule.cpp index 419efd7ff7..61962fa89c 100644 --- a/plugins/DbEditorPP/src/copymodule.cpp +++ b/plugins/DbEditorPP/src/copymodule.cpp @@ -31,7 +31,7 @@ INT_PTR CALLBACK copyModDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar mir_snwprintf(msg, TranslateT("Copy module \"%s\""), _A2T(mac->module)); SetWindowText(hwnd, msg); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { if (ApplyProtoFilter(hContact)) continue; @@ -61,7 +61,7 @@ INT_PTR CALLBACK copyModDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar } else { SetCursor(LoadCursor(nullptr, IDC_WAIT)); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) copyModule(mac->module, mac->hContact, hContact); SetCursor(LoadCursor(nullptr, IDC_ARROW)); diff --git a/plugins/DbEditorPP/src/deletemodule.cpp b/plugins/DbEditorPP/src/deletemodule.cpp index 41b3a123ed..5d3104d233 100644 --- a/plugins/DbEditorPP/src/deletemodule.cpp +++ b/plugins/DbEditorPP/src/deletemodule.cpp @@ -46,7 +46,8 @@ void __cdecl PopulateModuleDropListThreadFunc(void *param) module = module->next; continue; } - for (MCONTACT hContact = db_find_first(); moduleEmpty && hContact; hContact = db_find_next(hContact)) { + + for (auto &hContact : contact_iter()) { if (!IsModuleEmpty(hContact, module->name)) { SendDlgItemMessageA(hwnd, IDC_CONTACTS, CB_ADDSTRING, 0, (LPARAM)module->name); moduleEmpty = 0; @@ -93,7 +94,7 @@ INT_PTR CALLBACK DeleteModuleDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM) char module[FLD_SIZE]; GetDlgItemTextA(hwnd, IDC_CONTACTS, module, _countof(module)); SetCursor(LoadCursor(nullptr, IDC_WAIT)); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) deleteModule(hContact, module, 0); // do the null diff --git a/plugins/DbEditorPP/src/exportimport.cpp b/plugins/DbEditorPP/src/exportimport.cpp index e9c6efe468..82fc93f5eb 100644 --- a/plugins/DbEditorPP/src/exportimport.cpp +++ b/plugins/DbEditorPP/src/exportimport.cpp @@ -187,7 +187,6 @@ void exportDB(MCONTACT hContact, const char *module) fprintf(file, "\n\n"); while (hContact) { - if (ApplyProtoFilter(hContact)) { hContact = db_find_next(hContact); continue; @@ -257,7 +256,7 @@ MCONTACT CheckNewContact(const char *myProto, const char *uid, const char *myNam { char szProto[FLD_SIZE], szName[NAME_SIZE]; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) if (!db_get_static(hContact, "Protocol", "p", szProto, _countof(szProto))) if (!mir_strcmp(szProto, myProto)) if (GetValueA(hContact, szProto, uid, szName, _countof(szName)) && !mir_strcmp(szName, myName)) diff --git a/plugins/DbEditorPP/src/findwindow.cpp b/plugins/DbEditorPP/src/findwindow.cpp index ccfc80060a..ca09d1750c 100644 --- a/plugins/DbEditorPP/src/findwindow.cpp +++ b/plugins/DbEditorPP/src/findwindow.cpp @@ -404,8 +404,7 @@ void __cdecl FindSettings(LPVOID param) hContact = db_find_first(); } } - else - hContact = db_find_next(hContact); + else hContact = db_find_next(hContact); for (module = ModuleList.first; module; module = module->next) { diff --git a/plugins/DbEditorPP/src/modsettingenum.cpp b/plugins/DbEditorPP/src/modsettingenum.cpp index 79e734baf3..eef1292d39 100644 --- a/plugins/DbEditorPP/src/modsettingenum.cpp +++ b/plugins/DbEditorPP/src/modsettingenum.cpp @@ -160,7 +160,7 @@ int fixResidentSettings() fixing = 1; int cnt = 0; - for (MCONTACT hContact = db_find_first(); hContact != 0; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { for (ModSetLinkLinkItem *module = ModuleList.first; module; module = module->next) { if (IsModuleEmpty(hContact, module->name)) continue; diff --git a/plugins/DbEditorPP/src/moduletree.cpp b/plugins/DbEditorPP/src/moduletree.cpp index e23dfe866a..662c66ea85 100644 --- a/plugins/DbEditorPP/src/moduletree.cpp +++ b/plugins/DbEditorPP/src/moduletree.cpp @@ -46,9 +46,9 @@ int doContacts(HTREEITEM contactsRoot, ModuleSettingLL *modlist, MCONTACT hSelec char szProto[FLD_SIZE]; wchar_t name[NAME_SIZE]; - for (MCONTACT hContact = db_find_first(); hContact && hwnd2mainWindow; hContact = db_find_next(hContact)) { - - if (ApplyProtoFilter(hContact)) continue; + for (auto &hContact : contact_iter()) { + if (ApplyProtoFilter(hContact)) + continue; // add the contact lParam = (ModuleTreeInfoStruct *)mir_calloc(sizeof(ModuleTreeInfoStruct)); diff --git a/plugins/DbEditorPP/src/renamemodule.cpp b/plugins/DbEditorPP/src/renamemodule.cpp index 74e9e00a4a..c4b12f9b88 100644 --- a/plugins/DbEditorPP/src/renamemodule.cpp +++ b/plugins/DbEditorPP/src/renamemodule.cpp @@ -44,7 +44,7 @@ static INT_PTR CALLBACK AddModDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARA if (IsDlgButtonChecked(hwnd, CHK_ADD2ALL)) { // null contact db_set_b(NULL, modulename, "(Default)", 0); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) db_set_b(hContact, modulename, "(Default)", 0); } else db_set_b((MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA), modulename, "(Default)", 0); diff --git a/plugins/FavContacts/src/contact_cache.cpp b/plugins/FavContacts/src/contact_cache.cpp index 01af17ff40..534fe7009b 100644 --- a/plugins/FavContacts/src/contact_cache.cpp +++ b/plugins/FavContacts/src/contact_cache.cpp @@ -80,7 +80,7 @@ void CContactCache::Rebuild() unsigned long timestamp = time(nullptr); m_lastUpdate = time(nullptr); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { TContactInfo *info = new TContactInfo; info->hContact = hContact; info->rate = 0; diff --git a/plugins/FavContacts/src/favlist.h b/plugins/FavContacts/src/favlist.h index 394c7fb747..52c1679edf 100644 --- a/plugins/FavContacts/src/favlist.h +++ b/plugins/FavContacts/src/favlist.h @@ -111,7 +111,7 @@ public: nGroups = 1; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) if (db_get_b(hContact, "FavContacts", "IsFavourite", 0)) addContact(hContact, true); diff --git a/plugins/FavContacts/src/options.cpp b/plugins/FavContacts/src/options.cpp index 5a5ce392b7..c4e2ee901e 100644 --- a/plugins/FavContacts/src/options.cpp +++ b/plugins/FavContacts/src/options.cpp @@ -91,7 +91,7 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA hSelectedContact = db_find_first(); { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) SendDlgItemMessage(hwnd, IDC_CLIST, CLM_SETCHECKMARK, SendDlgItemMessage(hwnd, IDC_CLIST, CLM_FINDCONTACT, hContact, 0), db_get_b(hContact, "FavContacts", "IsFavourite", 0)); @@ -207,7 +207,7 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA sttSaveOptions(); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { BYTE fav = SendDlgItemMessage(hwnd, IDC_CLIST, CLM_GETCHECKMARK, SendDlgItemMessage(hwnd, IDC_CLIST, CLM_FINDCONTACT, hContact, 0), 0); if (fav != db_get_b(hContact, "FavContacts", "IsFavourite", 0)) @@ -225,7 +225,7 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA case CLN_NEWCONTACT: iSelection = (INT_PTR)((NMCLISTCONTROL *)lParam)->hItem; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { if (SendDlgItemMessage(hwnd, IDC_CLIST, CLM_FINDCONTACT, hContact, 0) == iSelection) { SendDlgItemMessage(hwnd, IDC_CLIST, CLM_SETCHECKMARK, iSelection, db_get_b(hContact, "FavContacts", "IsFavourite", 0)); @@ -236,7 +236,7 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA case CLN_CHECKCHANGED: iSelection = (INT_PTR)((NMCLISTCONTROL *)lParam)->hItem; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { if (SendDlgItemMessage(hwnd, IDC_CLIST, CLM_FINDCONTACT, hContact, 0) == iSelection) { hSelectedContact = hContact; RedrawWindow(GetDlgItem(hwnd, IDC_CANVAS), nullptr, nullptr, RDW_INVALIDATE); diff --git a/plugins/FavContacts/src/services.cpp b/plugins/FavContacts/src/services.cpp index 3c84800636..d221bdfc16 100644 --- a/plugins/FavContacts/src/services.cpp +++ b/plugins/FavContacts/src/services.cpp @@ -227,7 +227,7 @@ int ProcessModulesLoaded(WPARAM, LPARAM) Hotkey_Register(&hotkey); if (ServiceExists(MS_AV_GETAVATARBITMAP)) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) if (db_get_b(hContact, "FavContacts", "IsFavourite", 0)) CallService(MS_AV_GETAVATARBITMAP, hContact, 0); } diff --git a/plugins/FingerprintNG/src/options.cpp b/plugins/FingerprintNG/src/options.cpp index a18db89934..76482ee8b3 100644 --- a/plugins/FingerprintNG/src/options.cpp +++ b/plugins/FingerprintNG/src/options.cpp @@ -101,7 +101,7 @@ static INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LP ClearFI(); RegisterIcons(); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) OnExtraImageApply(hContact, 0); } break; diff --git a/plugins/FloatingContacts/src/main.cpp b/plugins/FloatingContacts/src/main.cpp index 80b435b9cd..e4fbafb88c 100644 --- a/plugins/FloatingContacts/src/main.cpp +++ b/plugins/FloatingContacts/src/main.cpp @@ -669,7 +669,7 @@ void SaveContactsPos() static void LoadContacts() { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) LoadContact(hContact); } diff --git a/plugins/GmailNotifier/src/utility.cpp b/plugins/GmailNotifier/src/utility.cpp index 840ff28a3c..bae5a91a74 100644 --- a/plugins/GmailNotifier/src/utility.cpp +++ b/plugins/GmailNotifier/src/utility.cpp @@ -4,7 +4,7 @@ void BuildList(void) { g_accs.destroy(); - for (MCONTACT hContact = db_find_first(MODULE_NAME); hContact; hContact = db_find_next(hContact, MODULE_NAME)) { + for (auto &hContact : contact_iter(MODULE_NAME)) { ptrA szName(db_get_sa(hContact, MODULE_NAME, "name")); if (szName != nullptr) { Account *p = new Account; diff --git a/plugins/HistoryStats/src/dlgoption_subexclude.cpp b/plugins/HistoryStats/src/dlgoption_subexclude.cpp index c0bf6e97f9..f94345ce7f 100644 --- a/plugins/HistoryStats/src/dlgoption_subexclude.cpp +++ b/plugins/HistoryStats/src/dlgoption_subexclude.cpp @@ -169,8 +169,7 @@ void DlgOption::SubExclude::saveSettings() db.setModule(con::ModHistoryStats); - MCONTACT hContact = db_find_first(); - while (hContact) { + for (auto &hContact : contact_iter()) { HANDLE hItem = reinterpret_cast(SendMessage(hCList, CLM_FINDCONTACT, hContact, 0)); if (hItem) { db.setContact(hContact); @@ -183,8 +182,6 @@ void DlgOption::SubExclude::saveSettings() else if (!bExcludeOld && iImage == 1) db.writeBool(con::SettExclude, true); } - - hContact = db_find_next(hContact); } // reset dirty flag @@ -243,8 +240,7 @@ void DlgOption::SubExclude::updateAllContacts(HWND hCList) db.setModule(con::ModHistoryStats); - MCONTACT hContact = db_find_first(); - while (hContact) { + for (auto &hContact : contact_iter()) { HANDLE hItem = reinterpret_cast(SendMessage(hCList, CLM_FINDCONTACT, hContact, 0)); if (hItem) { db.setContact(hContact); @@ -252,8 +248,6 @@ void DlgOption::SubExclude::updateAllContacts(HWND hCList) if (SendMessage(hCList, CLM_GETEXTRAIMAGE, reinterpret_cast(hItem), MAKELPARAM(0, 0)) == 0xFF) SendMessage(hCList, CLM_SETEXTRAIMAGE, reinterpret_cast(hItem), MAKELPARAM(0, db.settingExists(con::SettExclude) ? 1 : 0)); } - - hContact = db_find_next(hContact); } } diff --git a/plugins/HistoryStats/src/mirandahistory.cpp b/plugins/HistoryStats/src/mirandahistory.cpp index 93b834aa87..fe96757165 100644 --- a/plugins/HistoryStats/src/mirandahistory.cpp +++ b/plugins/HistoryStats/src/mirandahistory.cpp @@ -61,7 +61,7 @@ void MirandaHistory::readContacts() std::vector sources; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { db.setContact(hContact); const char* pProtoName = GetContactProto(hContact); diff --git a/plugins/HistorySweeperLight/src/historysweeperlight.cpp b/plugins/HistorySweeperLight/src/historysweeperlight.cpp index 62a6f3b102..c54268c5cc 100644 --- a/plugins/HistorySweeperLight/src/historysweeperlight.cpp +++ b/plugins/HistorySweeperLight/src/historysweeperlight.cpp @@ -201,7 +201,7 @@ void ShutdownAction(void) SweepHistoryFromContact(NULL, Criteria, FALSE); // sweep system history, keepunread==0 - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) SweepHistoryFromContact(hContact, Criteria, TRUE); // sweep contact history, keepunread==1 } diff --git a/plugins/HistorySweeperLight/src/options.cpp b/plugins/HistorySweeperLight/src/options.cpp index 60da041125..3100ea18ce 100644 --- a/plugins/HistorySweeperLight/src/options.cpp +++ b/plugins/HistorySweeperLight/src/options.cpp @@ -91,7 +91,7 @@ static void ShowAllContactIcons(HWND hwndList) SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hSystemHistory, MAKELPARAM(0, db_get_b(NULL, ModuleName, "SweepSHistory", 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); SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(0, db_get_b(hContact, ModuleName, "SweepHistory", 0))); @@ -150,7 +150,7 @@ void SaveSettings(HWND hwndDlg) db_set_b(NULL, ModuleName, "SweepSHistory", (BYTE)SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hSystemHistory, 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); int st = SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hItem, 0); diff --git a/plugins/IgnoreState/src/main.cpp b/plugins/IgnoreState/src/main.cpp index b99fcd0317..e5b30c0a39 100644 --- a/plugins/IgnoreState/src/main.cpp +++ b/plugins/IgnoreState/src/main.cpp @@ -135,7 +135,7 @@ int onModulesLoaded(WPARAM, LPARAM) fill_filter(); // Set initial value for all contacts - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) applyExtraImage(hContact); return 0; diff --git a/plugins/KeyboardNotify/src/ignore.cpp b/plugins/KeyboardNotify/src/ignore.cpp index 23a0e0d907..f476905a4d 100644 --- a/plugins/KeyboardNotify/src/ignore.cpp +++ b/plugins/KeyboardNotify/src/ignore.cpp @@ -171,7 +171,7 @@ static void SetAllContactIcons(HWND hwndList) { DWORD protoCaps; - 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) { char *szProto = GetContactProto(hContact); @@ -294,7 +294,7 @@ INT_PTR CALLBACK DlgProcIgnoreOptions(HWND hwndDlg, UINT msg, WPARAM, LPARAM lPa { 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"); diff --git a/plugins/ListeningTo/src/listeningto.cpp b/plugins/ListeningTo/src/listeningto.cpp index ad77475d8a..47c452af1a 100644 --- a/plugins/ListeningTo/src/listeningto.cpp +++ b/plugins/ListeningTo/src/listeningto.cpp @@ -178,7 +178,7 @@ int ModulesLoaded(WPARAM, LPARAM) EnableDisablePlayers(); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { char *proto = GetContactProto(hContact); if (proto != nullptr) { DBVARIANT dbv; diff --git a/plugins/ListeningTo/src/players/mradio.cpp b/plugins/ListeningTo/src/players/mradio.cpp index 60a88ec252..b65a7e2db4 100644 --- a/plugins/ListeningTo/src/players/mradio.cpp +++ b/plugins/ListeningTo/src/players/mradio.cpp @@ -34,7 +34,7 @@ void MRadio::EnableDisable() int MRadio::GetData() { - for (MCONTACT hContact = db_find_first("mRadio"); hContact; hContact = db_find_next(hContact, "mRadio")) { + for (auto &hContact : contact_iter("mRadio")) { WORD status = db_get_w(hContact, "mRadio", "Status", ID_STATUS_OFFLINE); if (status != ID_STATUS_ONLINE) continue; diff --git a/plugins/LotusNotify/src/LotusNotify.cpp b/plugins/LotusNotify/src/LotusNotify.cpp index 362811eed2..e93f6dc43e 100644 --- a/plugins/LotusNotify/src/LotusNotify.cpp +++ b/plugins/LotusNotify/src/LotusNotify.cpp @@ -1716,7 +1716,7 @@ extern "C" int __declspec(dllexport) Load(void) Proto_RegisterModule(&pd); // set all contacts to offline - for (MCONTACT hContact = db_find_first(PLUGINNAME); hContact; hContact = db_find_next(hContact, PLUGINNAME)) + for (auto &hContact : contact_iter(PLUGINNAME)) db_set_w(hContact, PLUGINNAME, "status", ID_STATUS_OFFLINE); CreateProtoServiceFunction(PLUGINNAME, PS_GETCAPS, GetCaps); diff --git a/plugins/MessageState/src/messagestate.cpp b/plugins/MessageState/src/messagestate.cpp index cace9a53ed..c5b628a10e 100644 --- a/plugins/MessageState/src/messagestate.cpp +++ b/plugins/MessageState/src/messagestate.cpp @@ -109,7 +109,7 @@ int OnModulesLoaded(WPARAM, LPARAM) InitClistExtraIcon(); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) IconsUpdate(hContact); return 0; diff --git a/plugins/MirFox/src/MirandaOptions.cpp b/plugins/MirFox/src/MirandaOptions.cpp index ed6857ff96..b57156d191 100644 --- a/plugins/MirFox/src/MirandaOptions.cpp +++ b/plugins/MirFox/src/MirandaOptions.cpp @@ -464,7 +464,7 @@ INT_PTR CALLBACK DlgProcOpts_Tab2(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM 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, IDC2_CONTACTS_LIST, CLM_FINDCONTACT, hContact, 0); if(hItem) { diff --git a/plugins/MirFox/src/MirandaUtils.cpp b/plugins/MirFox/src/MirandaUtils.cpp index 0e0592b242..5391d8063f 100644 --- a/plugins/MirFox/src/MirandaUtils.cpp +++ b/plugins/MirFox/src/MirandaUtils.cpp @@ -504,7 +504,7 @@ void MirandaUtils::translateOldDBNames() { } //contacts "state" - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)){ + for (auto &hContact : contact_iter()){ logger->log_p(L"TranslateOldDBNames: found CONTACT: [" SCNuPTR L"]", hContact); int keyValue = db_get_b(hContact, OLD_PLUGIN_DB_ID, "state", 0); diff --git a/plugins/MirFox/src/MirfoxData.cpp b/plugins/MirFox/src/MirfoxData.cpp index 5e7bd0809e..e63cdf25bb 100644 --- a/plugins/MirFox/src/MirfoxData.cpp +++ b/plugins/MirFox/src/MirfoxData.cpp @@ -631,7 +631,7 @@ void MirfoxData::initializeMirandaContacts() //get contects from miranda - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)){ + for (auto &hContact : contact_iter()){ //"Hidden" contacts not allowed in MirfoxData and SM, "NotOnList" contacts allowed and enabled if (db_get_b(hContact, "CList", "Hidden", 0) == 1) continue; diff --git a/plugins/MirOTR/src/dllmain.cpp b/plugins/MirOTR/src/dllmain.cpp index bb72c7746b..e39ec14d2f 100644 --- a/plugins/MirOTR/src/dllmain.cpp +++ b/plugins/MirOTR/src/dllmain.cpp @@ -82,7 +82,7 @@ extern "C" __declspec(dllexport) int Load(void) // remove us as a filter to all contacts - fix filter type problem if(db_get_b(0, MODULENAME, "FilterOrderFix", 0) != 2) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) Proto_RemoveFromContact(hContact, MODULENAME); db_set_b(0, MODULENAME, "FilterOrderFix", 2); } diff --git a/plugins/MirOTR/src/options.cpp b/plugins/MirOTR/src/options.cpp index 33b1ee0d35..8f57399a2d 100644 --- a/plugins/MirOTR/src/options.cpp +++ b/plugins/MirOTR/src/options.cpp @@ -548,7 +548,7 @@ static INT_PTR CALLBACK DlgProcMirOTROptsContacts(HWND hwndDlg, UINT msg, WPARAM // items. lvI.mask = LVIF_TEXT | LVIF_PARAM;// | LVIF_NORECOMPUTE;// | LVIF_IMAGE; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { const char *proto = GetContactProto(hContact); if (proto && db_get_b(hContact, proto, "ChatRoom", 0) == 0 && Proto_IsProtoOnContact(hContact, MODULENAME) // ignore chatrooms && mir_strcmp(proto, META_PROTO) != 0) // and MetaContacts diff --git a/plugins/MirOTR/src/utils.cpp b/plugins/MirOTR/src/utils.cpp index 00d34f226c..5c0c9d922e 100644 --- a/plugins/MirOTR/src/utils.cpp +++ b/plugins/MirOTR/src/utils.cpp @@ -9,7 +9,7 @@ void lib_cs_lock() MCONTACT find_contact(const char* userid, const char* protocol) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { const char *proto = GetContactProto(hContact); if(proto && mir_strcmp(proto, protocol) == 0) { char *name = contact_get_id(hContact); diff --git a/plugins/MirandaG15/src/CContactList.cpp b/plugins/MirandaG15/src/CContactList.cpp index 672e686129..e4000552a9 100644 --- a/plugins/MirandaG15/src/CContactList.cpp +++ b/plugins/MirandaG15/src/CContactList.cpp @@ -3,7 +3,7 @@ #include "CConfig.h" #include "CAppletManager.h" -const int aiStatusPriority[] = { 0, // ID_STATUS_OFFLINE 40071 +const int aiStatusPriority[] = { 0, // ID_STATUS_OFFLINE 40071 9, // ID_STATUS_ONLINE 40072 8, // ID_STATUS_AWAY 40073 1, // ID_STATUS_DND 40074 @@ -13,29 +13,29 @@ const int aiStatusPriority[] = { 0, // ID_STATUS_OFFLINE 40071 9, // ID_STATUS_INVISIBLE 40078 8, // ID_STATUS_ONTHEPHONE 40079 8 // ID_STATUS_OUTTOLUNCH 40080 - }; +}; //************************************************************************ // constructor //************************************************************************ -CContactList::CContactList() : m_bUseGroups(false), m_bUseMetaContacts(false), +CContactList::CContactList() + : m_bUseGroups(false), + m_bUseMetaContacts(false), m_dwLastScroll(0) -{ -} +{} //************************************************************************ // destructor //************************************************************************ CContactList::~CContactList() -{ -} +{} //************************************************************************ // initializes the list //************************************************************************ bool CContactList::Initialize() { - if(!CLCDList::Initialize()) + if (!CLCDList::Initialize()) return false; InitializeGroupObjects(); @@ -50,7 +50,7 @@ bool CContactList::Initialize() //************************************************************************ bool CContactList::Shutdown() { - if(!CLCDList::Shutdown()) + if (!CLCDList::Shutdown()) return false; UninitializeGroupObjects(); @@ -63,12 +63,12 @@ bool CContactList::Shutdown() //************************************************************************ // returns the contacts ccontactlistentry class //************************************************************************ -CContactListEntry *CContactList::GetContactData(CListEntry *pEntry) +CContactListEntry *CContactList::GetContactData(CListEntry *pEntry) { - if(pEntry->GetType() == ITEM) - return ((CListItem*)pEntry)->GetItemData(); + if (pEntry->GetType() == ITEM) + return ((CListItem*)pEntry)->GetItemData(); else - return ((CListContainer*)pEntry)->GetGroupData()->pContactListEntry; + return ((CListContainer*)pEntry)->GetGroupData()->pContactListEntry; } @@ -79,14 +79,13 @@ CContactListEntry *CContactList::GetContactData(CListEntry *pGroup = nullptr; + CListContainer *pGroup = nullptr; tstring strName = CAppletManager::GetContactDisplayname(hContact); char *szProto = GetContactProto(hContact); - + tstring strGroup = GetContactGroupPath(hContact); // ignore contacts without a valid protocoll - if(szProto == nullptr) + if (szProto == nullptr) return; - int iStatus = db_get_w(hContact,szProto,"Status",ID_STATUS_OFFLINE); + int iStatus = db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE); wchar_t *szStatus = pcli->pfnGetStatusModeDescription(iStatus, 0); CContactListEntry *psContact = new CContactListEntry(); @@ -116,120 +115,119 @@ void CContactList::AddContact(MCONTACT hContact) psContact->strName = strName; psContact->iMessages = 0; psContact->hHandle = hContact; - + psContact->iStatus = iStatus; - - if(szStatus != nullptr) - psContact->strStatus =toTstring(szStatus); + + if (szStatus != nullptr) + psContact->strStatus = toTstring(szStatus); psContact->strProto = toTstring(szProto); // check wether the contact should be listed - if(!IsVisible(psContact)) { + if (!IsVisible(psContact)) { delete psContact; return; } // Don't add metacontacts as contacts - if(!mir_strcmpi(szProto,"MetaContacts")) - { - if(!CConfig::GetBoolSetting(CLIST_USEGROUPS)) + if (!mir_strcmpi(szProto, "MetaContacts")) { + if (!CConfig::GetBoolSetting(CLIST_USEGROUPS)) strGroup = L""; - strGroup += (strGroup.empty()?L"":L"\\")+psContact->strName; + strGroup += (strGroup.empty() ? L"" : L"\\") + psContact->strName; pGroup = GetGroupByString(strGroup); - if(pGroup == nullptr) + if (pGroup == nullptr) pGroup = AddGroupByString(strGroup); pGroup->GetGroupData()->hMetaContact = hContact; pGroup->GetGroupData()->pContactListEntry = psContact; - pGroup = (CListContainer*)pGroup->GetParent(); - if(pGroup->GetType() != ROOT && iStatus != ID_STATUS_OFFLINE) - ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,1); + pGroup = (CListContainer*)pGroup->GetParent(); + if (pGroup->GetType() != ROOT && iStatus != ID_STATUS_OFFLINE) + ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath, 0, 1); pGroup->sort(CContactList::CompareEntries); // check that all subcontacts exist int numContacts = db_mc_getSubCount(hContact); MCONTACT hSubContact = NULL; - for(int i=0;i *pItem = nullptr; - if((!db_mc_isSub(hContact) && !CConfig::GetBoolSetting(CLIST_USEGROUPS)) || strGroup.empty()) - { + CListItem *pItem = nullptr; + if ((!db_mc_isSub(hContact) && !CConfig::GetBoolSetting(CLIST_USEGROUPS)) || strGroup.empty()) { pItem = AddItem(psContact); - ((CListContainer*)this)->sort(CContactList::CompareEntries); + ((CListContainer*)this)->sort(CContactList::CompareEntries); } - else - { + else { pGroup = GetGroupByString(strGroup); - if(pGroup == nullptr) { + if (pGroup == nullptr) { pGroup = AddGroupByString(strGroup); } pItem = pGroup->AddItem(psContact); - - if(!db_mc_isSub(hContact) && iStatus != ID_STATUS_OFFLINE) - ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,1); + + if (!db_mc_isSub(hContact) && iStatus != ID_STATUS_OFFLINE) + ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath, 0, 1); pGroup->sort(CContactList::CompareEntries); } - UpdateMessageCounter((CListEntry*)pItem); + UpdateMessageCounter((CListEntry*)pItem); } //************************************************************************ // returns wether a contact should be listed or not //************************************************************************ -bool CContactList::IsVisible(CContactListEntry *pEntry) { - if(!pEntry) { +bool CContactList::IsVisible(CContactListEntry *pEntry) +{ + if (!pEntry) { return false; } - - if(pEntry->strProto != L"MetaContacts") { - if(pEntry->iStatus == ID_STATUS_OFFLINE && CConfig::GetBoolSetting(CLIST_HIDEOFFLINE)) { + + if (pEntry->strProto != L"MetaContacts") { + if (pEntry->iStatus == ID_STATUS_OFFLINE && CConfig::GetBoolSetting(CLIST_HIDEOFFLINE)) { return false; } - } else { - if(pEntry->iStatus == ID_STATUS_OFFLINE) { + } + else { + if (pEntry->iStatus == ID_STATUS_OFFLINE) { int dwNumContacts = db_mc_getSubCount(pEntry->hHandle); - for(int i = 0; i < dwNumContacts; i++) { - MCONTACT hSubContact = db_mc_getSub(pEntry->hHandle,i); + for (int i = 0; i < dwNumContacts; i++) { + MCONTACT hSubContact = db_mc_getSub(pEntry->hHandle, i); char *szProto = GetContactProto(hSubContact); - if(db_get_w(hSubContact,szProto,"Status",ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) + if (db_get_w(hSubContact, szProto, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) return true; } } } - if(pEntry->iMessages > 0) + if (pEntry->iMessages > 0) return true; - if(CConfig::GetBoolSetting(CLIST_USEIGNORE)) { - if(db_get_b(pEntry->hHandle,"CList","Hidden",0)) + if (CConfig::GetBoolSetting(CLIST_USEIGNORE)) { + if (db_get_b(pEntry->hHandle, "CList", "Hidden", 0)) return false; - - if(db_mc_isSub(pEntry->hHandle)) { + + if (db_mc_isSub(pEntry->hHandle)) { MCONTACT hMetaContact = db_mc_getMeta(pEntry->hHandle); - if(db_get_b(hMetaContact,"CList","Hidden",0)) + if (db_get_b(hMetaContact, "CList", "Hidden", 0)) return false; } } - if(!CConfig::GetProtocolContactlistFilter(pEntry->strProto)) + if (!CConfig::GetProtocolContactlistFilter(pEntry->strProto)) return false; - if(CConfig::GetBoolSetting(CLIST_HIDEOFFLINE) && pEntry->iStatus == ID_STATUS_OFFLINE) + if (CConfig::GetBoolSetting(CLIST_HIDEOFFLINE) && pEntry->iStatus == ID_STATUS_OFFLINE) return false; return true; @@ -238,58 +236,57 @@ bool CContactList::IsVisible(CContactListEntry *pEntry) { //************************************************************************ // removes a contact from the list //************************************************************************ -void CContactList::RemoveContact(MCONTACT hContact) { - CListContainer *pGroup = nullptr; - +void CContactList::RemoveContact(MCONTACT hContact) +{ + CListContainer *pGroup = nullptr; + ///tstring strGroup = GetContactGroupPath(hContact); - CListEntry *pContactEntry = FindContact(hContact); - if(!pContactEntry) { + CListEntry *pContactEntry = FindContact(hContact); + if (!pContactEntry) return; - } - if( !CConfig::GetBoolSetting(CLIST_USEGROUPS)){ - if(pContactEntry->GetType() == ITEM) - RemoveItem(((CListItem*)pContactEntry)->GetItemData()); + if (!CConfig::GetBoolSetting(CLIST_USEGROUPS)) { + if (pContactEntry->GetType() == ITEM) + RemoveItem(((CListItem*)pContactEntry)->GetItemData()); else - RemoveGroup(((CListContainer*)pContactEntry)->GetGroupData()); - } else { - pGroup = (CListContainer*)pContactEntry->GetParent(); + RemoveGroup(((CListContainer*)pContactEntry)->GetGroupData()); + } + else { + pGroup = (CListContainer*)pContactEntry->GetParent(); ASSERT(pGroup != nullptr); - + CContactListEntry *pEntry = GetContactData(pContactEntry); - if(!pEntry) { + if (!pEntry) return; - } + // Update the contacts group if it has one - if(pGroup->GetType() != ROOT) - { - if(!db_mc_isSub(hContact) && pEntry->iStatus != ID_STATUS_OFFLINE) - ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,-1); - - if(!db_mc_isSub(hContact) && pEntry->iMessages > 0) - ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,0,-pEntry->iMessages); + if (pGroup->GetType() != ROOT) { + if (!db_mc_isSub(hContact) && pEntry->iStatus != ID_STATUS_OFFLINE) + ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath, 0, -1); + + if (!db_mc_isSub(hContact) && pEntry->iMessages > 0) + ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath, 0, 0, -pEntry->iMessages); } - if(pContactEntry->GetType() == ITEM) - pGroup->RemoveItem(((CListItem*)pContactEntry)->GetItemData()); + if (pContactEntry->GetType() == ITEM) + pGroup->RemoveItem(((CListItem*)pContactEntry)->GetItemData()); else { - pGroup->RemoveGroup(((CListContainer*)pContactEntry)->GetGroupData()); + pGroup->RemoveGroup(((CListContainer*)pContactEntry)->GetGroupData()); // Reenumerate all subcontacts (maybe MetaContacts was disabled int numContacts = db_mc_getSubCount(hContact); - for(int i=0;i *pParent = (CListContainer*)pGroup->GetParent(); - while(pParent != nullptr && pGroup->IsEmpty() && !pGroup->GetGroupData()->hMetaContact) - { + CListContainer *pParent = (CListContainer*)pGroup->GetParent(); + while (pParent != nullptr && pGroup->IsEmpty() && !pGroup->GetGroupData()->hMetaContact) { pParent->RemoveGroup(pGroup->GetGroupData()); pGroup = pParent; - pParent = (CListContainer*)pGroup->GetParent(); + pParent = (CListContainer*)pGroup->GetParent(); } } } @@ -297,49 +294,46 @@ void CContactList::RemoveContact(MCONTACT hContact) { //************************************************************************ // get group by string //************************************************************************ -CListContainer *CContactList::GetGroupByString(tstring strGroup) +CListContainer *CContactList::GetGroupByString(tstring strGroup) { tstring strParse = strGroup; - CListContainer *pGroup = (CListContainer*)this; + CListContainer *pGroup = (CListContainer*)this; tstring::size_type pos; - while((pos = strParse.find('\\')) != tstring::npos ) - { - strGroup = strParse.substr(0,pos); - strParse = strParse.substr(pos+1); - - pGroup = FindGroupInGroup(strGroup,pGroup); - if(pGroup == nullptr) + while ((pos = strParse.find('\\')) != tstring::npos) { + strGroup = strParse.substr(0, pos); + strParse = strParse.substr(pos + 1); + + pGroup = FindGroupInGroup(strGroup, pGroup); + if (pGroup == nullptr) return nullptr; } - pGroup = FindGroupInGroup(strParse,pGroup); + pGroup = FindGroupInGroup(strParse, pGroup); return pGroup; } //************************************************************************ // Adds a group //************************************************************************ -CListContainer *CContactList::AddGroupByString(tstring strGroup) +CListContainer *CContactList::AddGroupByString(tstring strGroup) { tstring strParse = strGroup; tstring strPath = L""; - CListContainer *pGroup = (CListContainer*)this; - CListContainer *pGroup2 = nullptr; + CListContainer *pGroup = (CListContainer*)this; + CListContainer *pGroup2 = nullptr; tstring::size_type pos; - while((pos = strParse.find('\\')) != tstring::npos ) - { - strGroup = strParse.substr(0,pos); - strParse = strParse.substr(pos+1); + while ((pos = strParse.find('\\')) != tstring::npos) { + strGroup = strParse.substr(0, pos); + strParse = strParse.substr(pos + 1); strPath += strGroup; - if(pGroup2 = FindGroupInGroup(strGroup,pGroup)) + if (pGroup2 = FindGroupInGroup(strGroup, pGroup)) pGroup = pGroup2; - else - { + else { CContactListGroup *pGroupObject = GetGroupObjectByPath(strPath); - if(!pGroupObject) + if (!pGroupObject) pGroupObject = CreateGroupObjectByPath(strPath); - pGroup2 = pGroup->InsertGroup(pGroup->begin(),pGroupObject); + pGroup2 = pGroup->InsertGroup(pGroup->begin(), pGroupObject); pGroup->sort(CContactList::CompareEntries); pGroup = pGroup2; } @@ -347,17 +341,15 @@ CListContainer *CContactList::AddGroupByS strPath += L"\\"; } strPath += strParse; - if(pGroup2 = FindGroupInGroup(strParse,pGroup)) + if (pGroup2 = FindGroupInGroup(strParse, pGroup)) return pGroup2; - else - { - CContactListGroup *pGroupObject = GetGroupObjectByPath(strPath); - if(!pGroupObject) - pGroupObject = CreateGroupObjectByPath(strPath); - pGroup2 = pGroup->InsertGroup(pGroup->begin(),pGroupObject); - pGroup->sort(CContactList::CompareEntries); - return pGroup2; - } + + CContactListGroup *pGroupObject = GetGroupObjectByPath(strPath); + if (!pGroupObject) + pGroupObject = CreateGroupObjectByPath(strPath); + pGroup2 = pGroup->InsertGroup(pGroup->begin(), pGroupObject); + pGroup->sort(CContactList::CompareEntries); + return pGroup2; } //************************************************************************ @@ -365,20 +357,17 @@ CListContainer *CContactList::AddGroupByS //************************************************************************ int CContactList::GetContactStatus(MCONTACT hContact) { - CListEntry *pContactEntry = FindContact(hContact); - if(!pContactEntry) + CListEntry *pContactEntry = FindContact(hContact); + if (!pContactEntry) return ID_STATUS_OFFLINE; - CContactListEntry *pEntry = GetContactData(pContactEntry); - if(!pEntry) { + if (!pEntry) return ID_STATUS_OFFLINE; - } + return pEntry->iStatus; } - - //************************************************************************ // Called to delete the specified item //************************************************************************ @@ -397,31 +386,30 @@ void CContactList::DeleteGroup(CContactListGroup*) //************************************************************************ // Called to draw the specified entry //************************************************************************ -void CContactList::DrawEntry(CLCDGfx *pGfx,CContactListEntry *pEntry,bool bSelected) +void CContactList::DrawEntry(CLCDGfx *pGfx, CContactListEntry *pEntry, bool bSelected) { - if(pEntry == nullptr) + if (pEntry == nullptr) return; tstring strText = L""; - if(pEntry->iMessages > 0) { + if (pEntry->iMessages > 0) { strText = L"["; strText += pEntry->strMessages; strText += L"]"; } strText += pEntry->strName; - if(CConfig::GetBoolSetting(CLIST_SHOWPROTO) && !CConfig::GetBoolSetting(CLIST_COLUMNS)) { + if (CConfig::GetBoolSetting(CLIST_SHOWPROTO) && !CConfig::GetBoolSetting(CLIST_COLUMNS)) { int w = pGfx->GetClipWidth(); - pGfx->DrawText(w-w*0.3,0,w*0.3,pEntry->strProto); - pGfx->DrawText(8,0,w*0.7-8,strText); + pGfx->DrawText(w - w * 0.3, 0, w*0.3, pEntry->strProto); + pGfx->DrawText(8, 0, w*0.7 - 8, strText); } - else pGfx->DrawText(8,0,pGfx->GetClipWidth()-8,strText); - - pGfx->DrawBitmap(1,ceil((pGfx->GetClipHeight()-5)/2.0f),5,5,CAppletManager::GetInstance()->GetStatusBitmap(pEntry->iStatus)); + else pGfx->DrawText(8, 0, pGfx->GetClipWidth() - 8, strText); - if(bSelected && (GetTickCount() - m_dwLastScroll < 1000 || !CConfig::GetBoolSetting(CLIST_SELECTION))) - { - RECT invert = { 0,0,GetWidth(),m_iFontHeight}; + pGfx->DrawBitmap(1, ceil((pGfx->GetClipHeight() - 5) / 2.0f), 5, 5, CAppletManager::GetInstance()->GetStatusBitmap(pEntry->iStatus)); + + if (bSelected && (GetTickCount() - m_dwLastScroll < 1000 || !CConfig::GetBoolSetting(CLIST_SELECTION))) { + RECT invert = { 0,0,GetWidth(),m_iFontHeight }; InvertRect(pGfx->GetHDC(), &invert); } } @@ -429,69 +417,62 @@ void CContactList::DrawEntry(CLCDGfx *pGfx,CContactListEntry *pEntry,bool bSelec //************************************************************************ // Called to draw the specified group //************************************************************************ -void CContactList::DrawGroup(CLCDGfx *pGfx,CContactListGroup *pGroup,bool bOpen,bool bSelected) +void CContactList::DrawGroup(CLCDGfx *pGfx, CContactListGroup *pGroup, bool bOpen, bool bSelected) { - if(pGroup == nullptr || ( pGroup->hMetaContact && pGroup->pContactListEntry == nullptr)) { + if (pGroup == nullptr || (pGroup->hMetaContact && pGroup->pContactListEntry == nullptr)) return; - } - char num[10],num2[10]; - itoa(pGroup->iMembers,num,10); - itoa(pGroup->iOnline,num2,10); + char num[10], num2[10]; + itoa(pGroup->iMembers, num, 10); + itoa(pGroup->iOnline, num2, 10); int iEvents = pGroup->iEvents; tstring strText = pGroup->strName; - if(!pGroup->hMetaContact) - { - if(CConfig::GetBoolSetting(CLIST_COUNTERS)) - strText = strText + L" (" + toTstring(num2).c_str()+ L"/" + toTstring(num).c_str() + L")"; + if (!pGroup->hMetaContact) { + if (CConfig::GetBoolSetting(CLIST_COUNTERS)) + strText = strText + L" (" + toTstring(num2).c_str() + L"/" + toTstring(num).c_str() + L")"; } - else - { - pGfx->DrawBitmap(8,ceil((pGfx->GetClipHeight()-5)/2.0f),5,5,CAppletManager::GetInstance()->GetStatusBitmap(pGroup->pContactListEntry->iStatus)); + else { + pGfx->DrawBitmap(8, ceil((pGfx->GetClipHeight() - 5) / 2.0f), 5, 5, CAppletManager::GetInstance()->GetStatusBitmap(pGroup->pContactListEntry->iStatus)); iEvents += pGroup->pContactListEntry->iMessages; } - if(iEvents != 0) - { - itoa(iEvents,num,10); + if (iEvents != 0) { + itoa(iEvents, num, 10); strText = L"[" + toTstring(num) + L"]" + strText; } - int iOffset = !pGroup->hMetaContact?m_iFontHeight*0.8:m_iFontHeight*0.8+8; - pGfx->DrawText(iOffset,0,pGfx->GetClipWidth()-iOffset,strText.c_str()); + int iOffset = !pGroup->hMetaContact ? m_iFontHeight * 0.8 : m_iFontHeight * 0.8 + 8; + pGfx->DrawText(iOffset, 0, pGfx->GetClipWidth() - iOffset, strText.c_str()); - if(bOpen) - pGfx->DrawText(1,0,L"-"); + if (bOpen) + pGfx->DrawText(1, 0, L"-"); else - pGfx->DrawText(1,0,L"+"); - - if(bSelected && (GetTickCount() - m_dwLastScroll < 1000|| !CConfig::GetBoolSetting(CLIST_SELECTION))) - { - RECT invert2 = { 0,0,GetWidth(),m_iFontHeight}; - InvertRect(pGfx->GetHDC(),&invert2); + pGfx->DrawText(1, 0, L"+"); + + if (bSelected && (GetTickCount() - m_dwLastScroll < 1000 || !CConfig::GetBoolSetting(CLIST_SELECTION))) { + RECT invert2 = { 0,0,GetWidth(),m_iFontHeight }; + InvertRect(pGfx->GetHDC(), &invert2); } } - //************************************************************************ // Called to compare two entrys //************************************************************************ -bool CContactList::CompareEntries(CListEntry *pLeft,CListEntry *pRight) +bool CContactList::CompareEntries(CListEntry *pLeft, CListEntry *pRight) { CContactListEntry *pLeftEntry = GetContactData(pLeft); CContactListEntry *pRightEntry = GetContactData(pRight); - if(pLeftEntry && pRightEntry) - { + if (pLeftEntry && pRightEntry) { int iLeftMessages = pLeftEntry->iMessages; int iRightMessages = pRightEntry->iMessages; - if(pLeft->GetType() == CONTAINER) - iLeftMessages += ((CListContainer*)pLeft)->GetGroupData()->iEvents; - if(pRight->GetType() == CONTAINER) - iRightMessages += ((CListContainer*)pRight)->GetGroupData()->iEvents; + if (pLeft->GetType() == CONTAINER) + iLeftMessages += ((CListContainer*)pLeft)->GetGroupData()->iEvents; + if (pRight->GetType() == CONTAINER) + iRightMessages += ((CListContainer*)pRight)->GetGroupData()->iEvents; if (!iRightMessages && iLeftMessages) return true; @@ -499,19 +480,18 @@ bool CContactList::CompareEntries(CListEntry iRightMessages); - else if(pLeftEntry->iStatus != pRightEntry->iStatus) + else if (pLeftEntry->iStatus != pRightEntry->iStatus) return (aiStatusPriority[pLeftEntry->iStatus - ID_STATUS_OFFLINE] > aiStatusPriority[pRightEntry->iStatus - ID_STATUS_OFFLINE]); else - return mir_wstrcmpi(pLeftEntry->strName.c_str(),pRightEntry->strName.c_str())<0; + return mir_wstrcmpi(pLeftEntry->strName.c_str(), pRightEntry->strName.c_str()) < 0; } - else if(pLeft->GetType() == ITEM && pRight->GetType() == CONTAINER) + else if (pLeft->GetType() == ITEM && pRight->GetType() == CONTAINER) return false; - else if(pLeft->GetType() == CONTAINER && pRight->GetType() == ITEM) + else if (pLeft->GetType() == CONTAINER && pRight->GetType() == ITEM) return true; - else if(pLeft->GetType() == CONTAINER && pRight->GetType() == CONTAINER) - { - CContactListGroup *pGroup1 = ((CListContainer*)pLeft)->GetGroupData(); - CContactListGroup *pGroup2 = ((CListContainer*)pRight)->GetGroupData(); + else if (pLeft->GetType() == CONTAINER && pRight->GetType() == CONTAINER) { + CContactListGroup *pGroup1 = ((CListContainer*)pLeft)->GetGroupData(); + CContactListGroup *pGroup2 = ((CListContainer*)pRight)->GetGroupData(); if (!pGroup2->iEvents && pGroup1->iEvents) return true; @@ -520,7 +500,7 @@ bool CContactList::CompareEntries(CListEntryiEvents && pGroup2->iEvents) return (pGroup1->iEvents > pGroup2->iEvents); else - return mir_wstrcmpi(pGroup1->strName.c_str(),pGroup2->strName.c_str())<0; + return mir_wstrcmpi(pGroup1->strName.c_str(), pGroup2->strName.c_str()) < 0; } return false; @@ -531,26 +511,24 @@ bool CContactList::CompareEntries(CListEntry *pContactEntry = nullptr; + CListEntry *pContactEntry = nullptr; MCONTACT hContact = db_find_first(); - while(hContact != NULL) - { + while (hContact != NULL) { pContactEntry = FindContact(hContact); - if(!pContactEntry) + if (!pContactEntry) AddContact(hContact); - else if(pContactEntry && !IsVisible(GetContactData(pContactEntry))) + else if (pContactEntry && !IsVisible(GetContactData(pContactEntry))) RemoveContact(hContact); - hContact = db_find_next(hContact); - } + hContact = db_find_next(hContact); + } } //************************************************************************ @@ -558,10 +536,10 @@ void CContactList::RefreshList() //************************************************************************ bool CContactList::SetFont(LOGFONT &lf) { - if(!CLCDList::SetFont(lf)) + if (!CLCDList::SetFont(lf)) return false; - SetEntryHeight(m_iFontHeight<5?5:m_iFontHeight); + SetEntryHeight(m_iFontHeight < 5 ? 5 : m_iFontHeight); return true; } @@ -574,28 +552,25 @@ void CContactList::OnConfigChanged() RefreshList(); } - //************************************************************************ // returns the entry for the specified group name //************************************************************************ -CListContainer *CContactList::FindGroup(tstring strGroup) +CListContainer *CContactList::FindGroup(tstring strGroup) { - return FindGroupInGroup(strGroup,(CListContainer*)this); + return FindGroupInGroup(strGroup, (CListContainer*)this); } //************************************************************************ // returns the entry for the specified group name //************************************************************************ -CListContainer *CContactList::FindGroupInGroup(tstring strGroup,CListContainer *pGroup) +CListContainer *CContactList::FindGroupInGroup(tstring strGroup, CListContainer *pGroup) { - CListContainer::iterator iter = pGroup->begin(); - CListContainer *pItem = nullptr; - while(!pGroup->empty() && iter != pGroup->end()) - { - if((*iter)->GetType() == CONTAINER) - { - pItem = (CListContainer*)*iter; - if(pItem->GetGroupData()->strName == strGroup) + CListContainer::iterator iter = pGroup->begin(); + CListContainer *pItem = nullptr; + while (!pGroup->empty() && iter != pGroup->end()) { + if ((*iter)->GetType() == CONTAINER) { + pItem = (CListContainer*)*iter; + if (pItem->GetGroupData()->strName == strGroup) return pItem; //pItem = FindGroupInGroup(strGroup,(CListContainer *)*iter); @@ -610,42 +585,39 @@ CListContainer *CContactList::FindGroupIn //************************************************************************ // returns the entry for the specified handle //************************************************************************ -CListEntry *CContactList::FindContact(MCONTACT hContact) +CListEntry *CContactList::FindContact(MCONTACT hContact) { - if(hContact == NULL) + if (hContact == NULL) return nullptr; - return FindContactInGroup(hContact,(CListContainer*)this); + return FindContactInGroup(hContact, (CListContainer*)this); } //************************************************************************ // returns the entry for the specified handle //************************************************************************ -CListEntry *CContactList::FindContactInGroup(MCONTACT hContact,CListContainer *pGroup) +CListEntry *CContactList::FindContactInGroup(MCONTACT hContact, CListContainer *pGroup) { - if(hContact == NULL) + if (hContact == NULL) return nullptr; - CListItem *pItemEntry = nullptr; - CListEntry *pEntry = nullptr; - CListContainer *pGroupEntry = nullptr; - CListContainer::iterator iter = pGroup->begin(); - while(iter != pGroup->end()) - { - if((*iter)->GetType() == ITEM) - { - pItemEntry = (CListItem*)*iter; - if(pItemEntry->GetItemData()->hHandle == hContact) + CListItem *pItemEntry = nullptr; + CListEntry *pEntry = nullptr; + CListContainer *pGroupEntry = nullptr; + CListContainer::iterator iter = pGroup->begin(); + while (iter != pGroup->end()) { + if ((*iter)->GetType() == ITEM) { + pItemEntry = (CListItem*)*iter; + if (pItemEntry->GetItemData()->hHandle == hContact) return *iter; } - else - { - pGroupEntry = (CListContainer *)*iter; - if(pGroupEntry->GetGroupData()->hMetaContact == hContact) + else { + pGroupEntry = (CListContainer *)*iter; + if (pGroupEntry->GetGroupData()->hMetaContact == hContact) return *iter; - pEntry = FindContactInGroup(hContact,pGroupEntry); - if(pEntry) + pEntry = FindContactInGroup(hContact, pGroupEntry); + if (pEntry) return pEntry; } iter++; @@ -659,17 +631,16 @@ CListEntry *CContactList::FindContactInGr //************************************************************************ void CContactList::OnContactHiddenChanged(MCONTACT hContact, bool bHidden) { - CListEntry *pContactEntry = FindContact(hContact); + CListEntry *pContactEntry = FindContact(hContact); - if(!pContactEntry && !bHidden) - { + if (!pContactEntry && !bHidden) { AddContact(hContact); return; } - else if(!pContactEntry) + else if (!pContactEntry) return; - if(!IsVisible(GetContactData(pContactEntry))) + if (!IsVisible(GetContactData(pContactEntry))) RemoveContact(hContact); } @@ -678,69 +649,65 @@ void CContactList::OnContactHiddenChanged(MCONTACT hContact, bool bHidden) //************************************************************************ void CContactList::OnContactNickChanged(MCONTACT hContact, tstring strNick) { - CListEntry *pContactEntry = FindContact(hContact); - if(!pContactEntry) + CListEntry *pContactEntry = FindContact(hContact); + if (!pContactEntry) return; - - if(pContactEntry->GetType() == CONTAINER) - { - CListContainer *pGroup = ((CListContainer*)pContactEntry); + + if (pContactEntry->GetType() == CONTAINER) { + CListContainer *pGroup = ((CListContainer*)pContactEntry); pGroup->GetGroupData()->strName = strNick; - tstring strPath = GetContactGroupPath(hContact); - pGroup->GetGroupData()->strPath = strPath + (strPath.empty()?L"":L"\\") + strNick; + tstring strPath = GetContactGroupPath(hContact); + pGroup->GetGroupData()->strPath = strPath + (strPath.empty() ? L"" : L"\\") + strNick; } CContactListEntry* pEntry = GetContactData(pContactEntry); - if(!pEntry) { + if (!pEntry) { return; } pEntry->strName = strNick; - ((CListContainer*)pContactEntry->GetParent())->sort(CContactList::CompareEntries); + ((CListContainer*)pContactEntry->GetParent())->sort(CContactList::CompareEntries); } //************************************************************************ // called when a contacts status has changed //************************************************************************ -void CContactList::OnStatusChange(MCONTACT hContact,int iStatus) +void CContactList::OnStatusChange(MCONTACT hContact, int iStatus) { // find the entry in the list - CListEntry *pContactEntry = FindContact(hContact); - if(!pContactEntry) - { + CListEntry *pContactEntry = FindContact(hContact); + if (!pContactEntry) { AddContact(hContact); return; } - - + + CContactListEntry *pItemData = GetContactData(pContactEntry); - if(!pItemData) { + if (!pItemData) { return; } // get the old status int iOldStatus = pItemData->iStatus; - + // Update the list entry wchar_t *szStatus = pcli->pfnGetStatusModeDescription(iStatus, 0); - if(szStatus != nullptr) - pItemData->strStatus =toTstring(szStatus); - + if (szStatus != nullptr) + pItemData->strStatus = toTstring(szStatus); + pItemData->iStatus = iStatus; - + // update the contacts group - CListContainer* pGroup = ((CListContainer*)pContactEntry->GetParent()); - if(pGroup->GetType() != ROOT) - { - if(!db_mc_isSub(hContact) && iStatus == ID_STATUS_OFFLINE && iOldStatus != ID_STATUS_OFFLINE) - ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,-1); - - else if(!db_mc_isSub(hContact) && iStatus != ID_STATUS_OFFLINE && iOldStatus == ID_STATUS_OFFLINE) - ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,1); + CListContainer* pGroup = ((CListContainer*)pContactEntry->GetParent()); + if (pGroup->GetType() != ROOT) { + if (!db_mc_isSub(hContact) && iStatus == ID_STATUS_OFFLINE && iOldStatus != ID_STATUS_OFFLINE) + ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath, 0, -1); + + else if (!db_mc_isSub(hContact) && iStatus != ID_STATUS_OFFLINE && iOldStatus == ID_STATUS_OFFLINE) + ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath, 0, 1); } - + // check if the entry is still visible - if(!IsVisible(pItemData)) - { + if (!IsVisible(pItemData)) { RemoveContact(hContact); return; } @@ -757,18 +724,17 @@ void CContactList::OnStatusChange(MCONTACT hContact,int iStatus) //************************************************************************ void CContactList::OnMessageCountChanged(MCONTACT hContact) { - CListEntry *pContactEntry = FindContact(hContact); - if(!pContactEntry) - { + CListEntry *pContactEntry = FindContact(hContact); + if (!pContactEntry) { AddContact(hContact); return; } UpdateMessageCounter(pContactEntry); - if(!IsVisible(GetContactData(pContactEntry))) + if (!IsVisible(GetContactData(pContactEntry))) RemoveContact(hContact); - ((CListContainer*)pContactEntry->GetParent())->sort(CContactList::CompareEntries); + ((CListContainer*)pContactEntry->GetParent())->sort(CContactList::CompareEntries); } @@ -782,14 +748,13 @@ void CContactList::OnContactAdded(MCONTACT hContact) // increase the membercount of the new group, and check if it needs to be created tstring strGroup = GetContactGroupPath(hContact); - if(!strGroup.empty()) - { + if (!strGroup.empty()) { CContactListGroup *pGroup = GetGroupObjectByPath(strGroup); - if(!pGroup) + if (!pGroup) pGroup = CreateGroupObjectByPath(strGroup); - - if(!db_mc_isSub(hContact)) - ChangeGroupObjectCounters(strGroup,1); + + if (!db_mc_isSub(hContact)) + ChangeGroupObjectCounters(strGroup, 1); } } @@ -803,15 +768,14 @@ void CContactList::OnContactDeleted(MCONTACT hContact) // Decrease the membercount of the old group, and check if it needs to be deleted tstring strGroup = GetContactGroupPath(hContact); - if(!strGroup.empty()) - { + if (!strGroup.empty()) { CContactListGroup *pGroup = GetGroupObjectByPath(strGroup); - - - if(!db_mc_isSub(hContact)) - ChangeGroupObjectCounters(strGroup,-1); - - if(pGroup && pGroup->iMembers <= 0) + + + if (!db_mc_isSub(hContact)) + ChangeGroupObjectCounters(strGroup, -1); + + if (pGroup && pGroup->iMembers <= 0) DeleteGroupObjectByPath(pGroup->strPath); } } @@ -819,53 +783,49 @@ void CContactList::OnContactDeleted(MCONTACT hContact) //************************************************************************ // called when a contacts group has changed //************************************************************************ -void CContactList::OnContactGroupChanged(MCONTACT hContact,tstring strGroup) +void CContactList::OnContactGroupChanged(MCONTACT hContact, tstring strGroup) { bool bMetaContact = false; - + strGroup = GetContactGroupPath(hContact); // Decrease the membercount of the old group - CListEntry *pContactEntry = FindContact(hContact); + CListEntry *pContactEntry = FindContact(hContact); CContactListGroup *pOldGroup = nullptr; // If the contactentry was not found, try adding the contact (metacontacts fix) - if(!pContactEntry) { + if (!pContactEntry) { return; } - if(pContactEntry->GetType() == CONTAINER) + if (pContactEntry->GetType() == CONTAINER) bMetaContact = true; - CListContainer* pContainer = ((CListContainer*)pContactEntry->GetParent()); + CListContainer* pContainer = ((CListContainer*)pContactEntry->GetParent()); // Update the contacts group if it has one - if(pContainer->GetType() != ROOT) - { + if (pContainer->GetType() != ROOT) { pOldGroup = pContainer->GetGroupData(); - if(!db_mc_isSub(hContact)) - ChangeGroupObjectCounters(pOldGroup->strPath,-1); + if (!db_mc_isSub(hContact)) + ChangeGroupObjectCounters(pOldGroup->strPath, -1); } - + // increase the membercount of the new group, and check if it needs to be created - if(!strGroup.empty()) - { + if (!strGroup.empty()) { CContactListGroup *pGroup = GetGroupObjectByPath(strGroup); - if(!pGroup) + if (!pGroup) pGroup = CreateGroupObjectByPath(strGroup); - if(!db_mc_isSub(hContact)) - ChangeGroupObjectCounters(strGroup,1); + if (!db_mc_isSub(hContact)) + ChangeGroupObjectCounters(strGroup, 1); } // move subcontacts - if(pContactEntry->GetType() == CONTAINER) - { - CListContainer *pGroup = (CListContainer*)pContactEntry; - CListContainer::iterator iter = pGroup->begin(); - while(!pGroup->empty()) - { + if (pContactEntry->GetType() == CONTAINER) { + CListContainer *pGroup = (CListContainer*)pContactEntry; + CListContainer::iterator iter = pGroup->begin(); + while (!pGroup->empty()) { iter = pGroup->begin(); - if((*iter)->GetType() == ITEM) - OnContactGroupChanged(GetContactData(*iter)->hHandle,L""); + if ((*iter)->GetType() == ITEM) + OnContactGroupChanged(GetContactData(*iter)->hHandle, L""); Sleep(1); } } @@ -874,85 +834,79 @@ void CContactList::OnContactGroupChanged(MCONTACT hContact,tstring strGroup) RemoveContact(hContact); AddContact(hContact); - if(bMetaContact) - { + if (bMetaContact) { tstring strName = CAppletManager::GetContactDisplayname(hContact); tstring strPath = L""; - if(pOldGroup) + if (pOldGroup) strPath += pOldGroup->strPath; - strPath += (strPath.empty()?L"":L"\\") + strName; + strPath += (strPath.empty() ? L"" : L"\\") + strName; DeleteGroupObjectByPath(strPath); } // check if the old group ( if it exists ) needs to be deleted - if(pOldGroup && !pOldGroup->hMetaContact && pOldGroup->iMembers <= 0 && pOldGroup->iGroups <= 0) + if (pOldGroup && !pOldGroup->hMetaContact && pOldGroup->iMembers <= 0 && pOldGroup->iGroups <= 0) DeleteGroupObjectByPath(pOldGroup->strPath); } //************************************************************************ // updates the message count for the specified contact //************************************************************************ -void CContactList::UpdateMessageCounter(CListEntry *pContactEntry) +void CContactList::UpdateMessageCounter(CListEntry *pContactEntry) { CContactListEntry *pEntry = GetContactData(pContactEntry); - if(!pEntry) { + if (!pEntry) { return; } int iOldMessages = pEntry->iMessages; bool bSort = false; MEVENT hEvent = db_event_firstUnread(pEntry->hHandle); - if(CAppletManager::IsMessageWindowOpen(pEntry->hHandle) || (hEvent == NULL && pEntry->iMessages > 0)) - { + if (CAppletManager::IsMessageWindowOpen(pEntry->hHandle) || (hEvent == NULL && pEntry->iMessages > 0)) { pEntry->iMessages = 0; bSort = true; } - else - { + else { pEntry->iMessages = 0; MEVENT hLastEvent = db_event_last(pEntry->hHandle); - while(hLastEvent != NULL && hEvent != NULL) - { + while (hLastEvent != NULL && hEvent != NULL) { pEntry->iMessages++; - if(hLastEvent == hEvent) + if (hLastEvent == hEvent) break; hLastEvent = db_event_prev(pEntry->hHandle, hLastEvent); } } - if(pEntry->iMessages >= 100) + if (pEntry->iMessages >= 100) pEntry->strMessages = L">99"; - else - { + else { char buffer[8]; buffer[0] = 0; - itoa(pEntry->iMessages,buffer,10); + itoa(pEntry->iMessages, buffer, 10); pEntry->strMessages = toTstring(buffer); } - CListContainer* pContainer = ((CListContainer*)pContactEntry->GetParent()); + CListContainer* pContainer = ((CListContainer*)pContactEntry->GetParent()); // Update the contacts group if it has one - if(pContainer->GetType() != ROOT) - { + if (pContainer->GetType() != ROOT) { // Update the groups event count - if(iOldMessages != 0 && pEntry->iMessages == 0) - ChangeGroupObjectCounters(pContainer->GetGroupData()->strPath,0,0,-1); - else if(iOldMessages == 0 && pEntry->iMessages != 0) - ChangeGroupObjectCounters(pContainer->GetGroupData()->strPath,0,0,1); + if (iOldMessages != 0 && pEntry->iMessages == 0) + ChangeGroupObjectCounters(pContainer->GetGroupData()->strPath, 0, 0, -1); + else if (iOldMessages == 0 && pEntry->iMessages != 0) + ChangeGroupObjectCounters(pContainer->GetGroupData()->strPath, 0, 0, 1); else return; - + // sort the groups parent - ((CListContainer*)pContainer->GetParent())->sort(CContactList::CompareEntries); + ((CListContainer*)pContainer->GetParent())->sort(CContactList::CompareEntries); } } //************************************************************************ // changes the groups membercount //************************************************************************ -void CContactList::ChangeGroupObjectCounters(tstring strGroup,int iMembers,int iOnline,int iEvents) +void CContactList::ChangeGroupObjectCounters(tstring strGroup, int iMembers, int iOnline, int iEvents) { CContactListGroup* pGroup = GetGroupObjectByPath(strGroup); - if(!pGroup) + if (!pGroup) return; pGroup->iMembers += iMembers; @@ -962,17 +916,16 @@ void CContactList::ChangeGroupObjectCounters(tstring strGroup,int iMembers,int i tstring strParse = pGroup->strPath; tstring::size_type pos; - while((pos = strParse.rfind('\\')) != tstring::npos ) - { - strParse = strParse.substr(0,pos); + while ((pos = strParse.rfind('\\')) != tstring::npos) { + strParse = strParse.substr(0, pos); pGroup = GetGroupObjectByPath(strParse); - if(!pGroup) + if (!pGroup) break; pGroup->iMembers += iMembers; pGroup->iOnline += iOnline; pGroup->iEvents += iEvents; - } + } } //************************************************************************ @@ -981,8 +934,7 @@ void CContactList::ChangeGroupObjectCounters(tstring strGroup,int iMembers,int i void CContactList::UninitializeGroupObjects() { vector::iterator iter = m_Groups.begin(); - while(iter != m_Groups.end()) - { + while (iter != m_Groups.end()) { delete (*iter); iter++; } @@ -995,39 +947,36 @@ void CContactList::UninitializeGroupObjects() void CContactList::InitializeGroupObjects() { UninitializeGroupObjects(); - - for(MCONTACT hContact = db_find_first();hContact != NULL;hContact = db_find_next(hContact)) - { + + for (MCONTACT hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) { tstring strGroup = GetContactGroupPath(hContact); char *szProto = GetContactProto(hContact); - if(szProto && db_get_b(NULL,META_PROTO,"Enabled",1) && !mir_strcmpi(szProto,META_PROTO)) - { + if (szProto && db_get_b(NULL, META_PROTO, "Enabled", 1) && !mir_strcmpi(szProto, META_PROTO)) { tstring strName = CAppletManager::GetContactDisplayname(hContact); tstring strPath = L""; - if(CConfig::GetBoolSetting(CLIST_USEGROUPS)) + if (CConfig::GetBoolSetting(CLIST_USEGROUPS)) strPath += strGroup; - strPath += (strPath.empty()?L"":L"\\") + strName; + strPath += (strPath.empty() ? L"" : L"\\") + strName; CContactListGroup *pGroup = CreateGroupObjectByPath(strPath); pGroup->hMetaContact = hContact; - if(!strGroup.empty()) - ChangeGroupObjectCounters(strGroup,1); + if (!strGroup.empty()) + ChangeGroupObjectCounters(strGroup, 1); } // If the contact has no group, continue - else if(!strGroup.empty() && CConfig::GetBoolSetting(CLIST_USEGROUPS)) - { + else if (!strGroup.empty() && CConfig::GetBoolSetting(CLIST_USEGROUPS)) { CContactListGroup *pGroup = GetGroupObjectByPath(strGroup); // create the group - if(!pGroup) + if (!pGroup) CreateGroupObjectByPath(strGroup); // update it's counters - if(!db_mc_isSub(hContact)) - ChangeGroupObjectCounters(strGroup,1); + if (!db_mc_isSub(hContact)) + ChangeGroupObjectCounters(strGroup, 1); } - } + } } //************************************************************************ @@ -1039,10 +988,8 @@ CContactListGroup *CContactList::GetGroupObjectByPath(tstring strPath) CContactListGroup *pGroup = nullptr; vector::iterator iter = m_Groups.begin(); - for(;iter != m_Groups.end();iter++) - { - if((*iter)->strPath == strPath) - { + for (; iter != m_Groups.end(); iter++) { + if ((*iter)->strPath == strPath) { pGroup = *iter; break; } @@ -1064,18 +1011,17 @@ CContactListGroup *CContactList::CreateGroupObjectByPath(tstring strPath) tstring strName = strPath; tstring::size_type pos; - while((pos = strName.find('\\')) != tstring::npos ) - { - strParsePath += strName.substr(0,pos); - strName = strName.substr(pos+1); - + while ((pos = strName.find('\\')) != tstring::npos) { + strParsePath += strName.substr(0, pos); + strName = strName.substr(pos + 1); + pParentGroup = GetGroupObjectByPath(strParsePath); - if(!pParentGroup) + if (!pParentGroup) pParentGroup = CreateGroupObjectByPath(strParsePath); strParsePath += L"\\"; } - - if(pParentGroup) + + if (pParentGroup) pParentGroup->iGroups++; pNewGroup->strName = strName; @@ -1099,22 +1045,17 @@ void CContactList::DeleteGroupObjectByPath(tstring strPath) { ASSERT(!strPath.empty()); - for(vector::iterator iter = m_Groups.begin();iter != m_Groups.end();iter++) - { - if((*iter)->strPath == strPath) - { + for (vector::iterator iter = m_Groups.begin(); iter != m_Groups.end(); iter++) { + if ((*iter)->strPath == strPath) { CContactListGroup *pGroup = *iter; m_Groups.erase(iter); - if(pGroup->pContactListEntry) - { + if (pGroup->pContactListEntry) DeleteEntry(pGroup->pContactListEntry); - } delete pGroup; tstring strParse = strPath; tstring::size_type pos = strParse.rfind('\\'); - if (pos != tstring::npos) - { + if (pos != tstring::npos) { strParse = strParse.substr(0, pos); CContactListGroup *pParentGroup = GetGroupObjectByPath(strParse); if (pParentGroup) { @@ -1128,23 +1069,24 @@ void CContactList::DeleteGroupObjectByPath(tstring strPath) } } -void CContactList::SetPosition(CListEntry *pEntry) +void CContactList::SetPosition(CListEntry *pEntry) { - CLCDList::SetPosition(pEntry); + CLCDList::SetPosition(pEntry); } bool CContactList::ScrollUp() { m_dwLastScroll = GetTickCount(); - return CLCDList::ScrollUp(); + return CLCDList::ScrollUp(); } bool CContactList::ScrollDown() { m_dwLastScroll = GetTickCount(); - return CLCDList::ScrollDown(); + return CLCDList::ScrollDown(); } -void CContactList::ShowSelection() { +void CContactList::ShowSelection() +{ m_dwLastScroll = GetTickCount(); -} \ No newline at end of file +} diff --git a/plugins/MobileState/src/main.cpp b/plugins/MobileState/src/main.cpp index e59a4b8578..64928c8213 100644 --- a/plugins/MobileState/src/main.cpp +++ b/plugins/MobileState/src/main.cpp @@ -96,7 +96,7 @@ int onContactSettingChanged(WPARAM wParam, LPARAM lParam) int onModulesLoaded(WPARAM, LPARAM) { // Set initial value for all contacts - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) ExtraIconsApply(hContact, 1); return 0; diff --git a/plugins/Msg_Export/src/options.cpp b/plugins/Msg_Export/src/options.cpp index 51b53fe797..a769468e64 100755 --- a/plugins/Msg_Export/src/options.cpp +++ b/plugins/Msg_Export/src/options.cpp @@ -626,7 +626,7 @@ static INT_PTR CALLBACK DlgProcMsgExportOpts(HWND hwndDlg, UINT msg, WPARAM wPar int nUser = 0; tstring sTmp; LVITEM sItem = { 0 }; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { PROTOACCOUNT *pa = Proto_GetAccount(GetContactProto(hContact)); if (pa == nullptr) continue; diff --git a/plugins/Msg_Export/src/utils.cpp b/plugins/Msg_Export/src/utils.cpp index 7024e28f42..a6c772801c 100755 --- a/plugins/Msg_Export/src/utils.cpp +++ b/plugins/Msg_Export/src/utils.cpp @@ -787,7 +787,7 @@ void UpdateFileToColWidth() { clFileTo1ColWidth.clear(); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { tstring sNick = pcli->pfnGetContactDisplayName(hContact, 0); string::size_type &rnValue = clFileTo1ColWidth[GetFilePathFromUser(hContact)]; if (rnValue < sNick.size()) @@ -1395,7 +1395,7 @@ int nContactDeleted(WPARAM wparam, LPARAM /*lparam*/) tstring sFilePath = GetFilePathFromUser(hContact); // Test if there is another user using this file - for (MCONTACT hOtherContact = db_find_first(); hOtherContact; hOtherContact = db_find_next(hOtherContact)) + for (auto &hOtherContact : contact_iter()) if (hContact != hOtherContact && sFilePath == GetFilePathFromUser(hOtherContact)) return 0; // we found another contact abort mission :-) diff --git a/plugins/NewAwaySysMod/src/AwayOpt.cpp b/plugins/NewAwaySysMod/src/AwayOpt.cpp index 0b413d290e..16e8b4d3ba 100644 --- a/plugins/NewAwaySysMod/src/AwayOpt.cpp +++ b/plugins/NewAwaySysMod/src/AwayOpt.cpp @@ -853,8 +853,7 @@ static void SetAllContactIcons(HWND hwndList, HANDLE hItemUnknown) SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItemUnknown, MAKELPARAM(IGNORECOLUMN, DBValueToIgnoreIcon(CContactSettings(ID_STATUS_ONLINE, INVALID_CONTACT_ID).Ignore))); SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItemUnknown, MAKELPARAM(AUTOREPLYCOLUMN, DBValueToOptReplyIcon(CContactSettings(ID_STATUS_ONLINE, INVALID_CONTACT_ID).Autoreply))); - MCONTACT hContact = db_find_first(); - do { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0); if (hItem) { int Ignore = CContactSettings(ID_STATUS_ONLINE, hContact).Ignore; @@ -873,7 +872,6 @@ static void SetAllContactIcons(HWND hwndList, HANDLE hItemUnknown) SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(AUTOREPLYCOLUMN, DBValueToOptReplyIcon(Reply))); } } - while (hContact = db_find_next(hContact)); } static LRESULT CALLBACK ContactsSubclassProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) @@ -922,8 +920,8 @@ INT_PTR CALLBACK ContactsOptDlg(HWND hwndDlg, UINT msg, WPARAM, LPARAM lParam) hItemAll = (HANDLE)SendMessage(hwndList, CLM_ADDINFOITEM, 0, (LPARAM)&cii); cii.pszText = TranslateT("** Not-on-list contacts **"); // == Unknown contacts hItemUnknown = (HANDLE)SendMessage(hwndList, CLM_ADDINFOITEM, 0, (LPARAM)&cii); - MCONTACT hContact = db_find_first(); - do { + + for (auto &hContact : contact_iter()) { char *szProto = GetContactProto(hContact); if (szProto) { int Flag1 = CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0); @@ -931,7 +929,7 @@ INT_PTR CALLBACK ContactsOptDlg(HWND hwndDlg, UINT msg, WPARAM, LPARAM lParam) SendMessage(hwndList, CLM_DELETEITEM, SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0), 0); } } - while (hContact = db_find_next(hContact)); + SetAllContactIcons(hwndList, hItemUnknown); SetListGroupIcons(hwndList, (HANDLE)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_ROOT, 0), hItemAll); g_OrigContactsProc = (WNDPROC)SetWindowLongPtr(hwndList, GWLP_WNDPROC, (LONG_PTR)ContactsSubclassProc); @@ -997,7 +995,7 @@ INT_PTR CALLBACK ContactsOptDlg(HWND hwndDlg, UINT msg, WPARAM, LPARAM 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)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0); if (hItem) SaveItemState(hwndList, hContact, hItem); diff --git a/plugins/NewAwaySysMod/src/AwaySys.cpp b/plugins/NewAwaySysMod/src/AwaySys.cpp index fd339acc69..37f378319d 100644 --- a/plugins/NewAwaySysMod/src/AwaySys.cpp +++ b/plugins/NewAwaySysMod/src/AwaySys.cpp @@ -133,7 +133,7 @@ int StatusMsgReq(WPARAM wParam, LPARAM lParam, CString &szProto) // find the contact char *szFoundProto; MCONTACT hFoundContact = NULL; // if we'll find the contact only on some other protocol, but not on szProto, then we'll use that hContact. - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { char *szCurProto = GetContactProto(hContact); if (db_get_dw(hContact, szCurProto, "UIN", 0) == lParam) { szFoundProto = szCurProto; diff --git a/plugins/NewAwaySysMod/src/Properties.cpp b/plugins/NewAwaySysMod/src/Properties.cpp index 7fc0fa32a5..64b6ac0f83 100644 --- a/plugins/NewAwaySysMod/src/Properties.cpp +++ b/plugins/NewAwaySysMod/src/Properties.cpp @@ -34,16 +34,13 @@ void ResetSettingsOnStatusChange(const char *szProto = nullptr, int bResetPerson if (bResetPersonalMsgs) bResetPersonalMsgs = !g_MoreOptPage.GetDBValueCopy(IDC_MOREOPTDLG_SAVEPERSONALMSGS); - MCONTACT hContact = db_find_first(); - while (hContact) { + for (auto &hContact : contact_iter()) { const char *szCurProto; if (!szProto || ((szCurProto = GetContactProto(hContact)) && !mir_strcmp(szProto, szCurProto))) { ResetContactSettingsOnStatusChange(hContact); - if (bResetPersonalMsgs) { + if (bResetPersonalMsgs) CContactSettings(Status, hContact).SetMsgFormat(SMF_PERSONAL, nullptr); // TODO: delete only when SAM dialog opens? - } } - hContact = db_find_next(hContact); } } diff --git a/plugins/NewAwaySysMod/src/SetAwayMsg.cpp b/plugins/NewAwaySysMod/src/SetAwayMsg.cpp index 26fb5a2db7..e953b125c3 100644 --- a/plugins/NewAwaySysMod/src/SetAwayMsg.cpp +++ b/plugins/NewAwaySysMod/src/SetAwayMsg.cpp @@ -878,9 +878,8 @@ INT_PTR CALLBACK SetAwayMsgDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA } } - MCONTACT hContact = db_find_first(); CList->SetRedraw(false); - do { + for (auto &hContact : contact_iter()) { char *szProto = GetContactProto(hContact); if (szProto) { int Flag1 = CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0); @@ -891,7 +890,6 @@ INT_PTR CALLBACK SetAwayMsgDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA } } } - while (hContact = db_find_next(hContact)); CList->SortContacts(); hItem = CLC_ROOT; diff --git a/plugins/NewXstatusNotify/src/indsnd.cpp b/plugins/NewXstatusNotify/src/indsnd.cpp index 9e6224f92b..29e9bf0787 100644 --- a/plugins/NewXstatusNotify/src/indsnd.cpp +++ b/plugins/NewXstatusNotify/src/indsnd.cpp @@ -301,7 +301,7 @@ void SetAllContactsIcons(HWND hwndList) { BYTE EnableSounds, EnablePopups, EnableXStatus, EnableXLogging, EnableStatusMsg, EnableSMsgLogging; - 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) { char *szProto = GetContactProto(hContact); @@ -542,7 +542,7 @@ INT_PTR CALLBACK DlgProcFiltering(HWND hwndDlg, UINT msg, WPARAM, LPARAM 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)SendMessage(hList, CLM_FINDCONTACT, hContact, 0); if (hItem) { if (GetExtraImage(hList, hItem, EXTRA_IMAGE_SOUND) == EXTRA_IMAGE_SOUND) diff --git a/plugins/New_GPG/src/icons.cpp b/plugins/New_GPG/src/icons.cpp index 8fec21dd53..87faa64938 100755 --- a/plugins/New_GPG/src/icons.cpp +++ b/plugins/New_GPG/src/icons.cpp @@ -68,7 +68,7 @@ void setSrmmIcon(MCONTACT h) void RefreshContactListIcons() { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) setClistIcon(hContact); Clist_EndRebuild(); diff --git a/plugins/New_GPG/src/options.cpp b/plugins/New_GPG/src/options.cpp index 4aa3d0bb7f..07e3840372 100755 --- a/plugins/New_GPG/src/options.cpp +++ b/plugins/New_GPG/src/options.cpp @@ -59,10 +59,8 @@ public: list_USERLIST.AddColumn(4, TranslateT("Protocol"), 60); list_USERLIST.SetExtendedListViewStyle(LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_SINGLEROW); int i = 1; - for (MCONTACT hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) - { - if (isContactHaveKey(hContact)) - { + for (auto &hContact : contact_iter()) { + if (isContactHaveKey(hContact)) { wchar_t *name = pcli->pfnGetContactDisplayName(hContact, 0); int row = list_USERLIST.AddItem(L"", 0); @@ -173,7 +171,7 @@ public: ismetacontact = true; } tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); - for (MCONTACT hcnttmp = db_find_first(); hcnttmp != NULL; hcnttmp = db_find_next(hcnttmp)) { + for (auto &hcnttmp : contact_iter()) { if (hcnttmp != hContact) { char *tmp2 = UniGetContactSettingUtf(hcnttmp, szGPGModuleName, "KeyID", ""); if (!mir_strcmp(tmp, tmp2)) { diff --git a/plugins/New_GPG/src/utilities.cpp b/plugins/New_GPG/src/utilities.cpp index d82259f9c8..99eb4e35f7 100755 --- a/plugins/New_GPG/src/utilities.cpp +++ b/plugins/New_GPG/src/utilities.cpp @@ -1249,7 +1249,7 @@ void ExportGpGKeysFunc(int type) if (!file.is_open()) return; //TODO: handle error if (!type || type == 2) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { char *k = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", ""); std::string key; if (!k[0]) { @@ -1531,7 +1531,7 @@ INT_PTR ImportGpGKeys(WPARAM, LPARAM) } if (acc.length()) { const char * uid = (const char*)CallProtoService(acc.c_str(), PS_GETCAPS, (WPARAM)PFLAG_UNIQUEIDSETTING, 0); - for (MCONTACT hContact = db_find_first(acc.c_str()); hContact; hContact = db_find_next(hContact, acc.c_str())) { + for (auto &hContact : contact_iter(acc.c_str())) { DBVARIANT dbv = { 0 }; db_get(hContact, acc.c_str(), uid, &dbv); std::string id; 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; diff --git a/plugins/NoHistory/src/options.cpp b/plugins/NoHistory/src/options.cpp index 92877a43b7..592a2dbbd2 100644 --- a/plugins/NoHistory/src/options.cpp +++ b/plugins/NoHistory/src/options.cpp @@ -77,7 +77,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()) { char *proto = GetContactProto(hContact); bool chat_room = (proto && db_get_b(hContact, proto, "ChatRoom", 0) != 0); @@ -191,7 +191,7 @@ static INT_PTR CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA 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()) { char *proto = GetContactProto(hContact); bool chat_room = (proto && db_get_b(hContact, proto, "ChatRoom", 0) != 0); diff --git a/plugins/Non-IM Contact/src/files.cpp b/plugins/Non-IM Contact/src/files.cpp index 232532dc4a..b7e45a7154 100644 --- a/plugins/Non-IM Contact/src/files.cpp +++ b/plugins/Non-IM Contact/src/files.cpp @@ -14,7 +14,7 @@ INT_PTR exportContacts(WPARAM, LPARAM) if (!file) return 0; - for (MCONTACT hContact = db_find_first(MODNAME); hContact; hContact = db_find_next(hContact, MODNAME)) { + for (auto &hContact : contact_iter(MODNAME)) { int tmp; char DBVar[1024]; if (!db_get_static(hContact, MODNAME, "Name", DBVar, _countof(DBVar))) { diff --git a/plugins/Non-IM Contact/src/services.cpp b/plugins/Non-IM Contact/src/services.cpp index 46282ef90a..649ae0100b 100644 --- a/plugins/Non-IM Contact/src/services.cpp +++ b/plugins/Non-IM Contact/src/services.cpp @@ -62,7 +62,7 @@ int SetLCStatus(WPARAM wParam, LPARAM) else if (db_get_w(NULL, MODNAME, "Timer", 1)) startTimer(TIMER); - for (MCONTACT hContact = db_find_first(MODNAME); hContact; hContact = db_find_next(hContact, MODNAME)) { + for (auto &hContact : contact_iter(MODNAME)) { if (LCStatus != ID_STATUS_OFFLINE) replaceAllStrings(hContact); diff --git a/plugins/Non-IM Contact/src/timer.cpp b/plugins/Non-IM Contact/src/timer.cpp index dc20309a9b..31b9616c46 100644 --- a/plugins/Non-IM Contact/src/timer.cpp +++ b/plugins/Non-IM Contact/src/timer.cpp @@ -40,7 +40,7 @@ void timerFunc(void*) } /* update all the contacts */ - for (MCONTACT hContact = db_find_first(MODNAME); hContact; hContact = db_find_next(hContact, MODNAME)) { + for (auto &hContact : contact_iter(MODNAME)) { int timer = db_get_w(hContact, MODNAME, "Timer", 15); if (timer && !(timerCount % timer)) if (!db_get_static(hContact, MODNAME, "Name", text, _countof(text))) diff --git a/plugins/Popup/src/opt_contacts.cpp b/plugins/Popup/src/opt_contacts.cpp index 0bb94612f6..d42762c740 100644 --- a/plugins/Popup/src/opt_contacts.cpp +++ b/plugins/Popup/src/opt_contacts.cpp @@ -30,7 +30,7 @@ static void sttResetListOptions(HWND hwndList) static void sttSetAllContactIcons(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); DWORD dwMode = db_get_b(hContact, MODULNAME, "ShowMode", 0); for (int i = 0; i < 4 /*_countof(sttIcons)*/; ++i) @@ -99,7 +99,7 @@ INT_PTR CALLBACK DlgProcContactOpts(HWND hwnd, UINT msg, WPARAM, LPARAM lParam) switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: HWND hwndList = GetDlgItem(hwnd, IDC_LIST); - 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); for (int i = 0; i < 4 /*_countof(sttIcons)*/; ++i) { if (SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(i, 0))) { diff --git a/plugins/QuickContacts/src/quickcontacts.cpp b/plugins/QuickContacts/src/quickcontacts.cpp index 9f864e2bc7..5ac56f6adb 100644 --- a/plugins/QuickContacts/src/quickcontacts.cpp +++ b/plugins/QuickContacts/src/quickcontacts.cpp @@ -328,7 +328,7 @@ void LoadContacts(HWND hwndDlg, BOOL show_all) // item data of listbox-strings is the array position FreeContacts(); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { char *pszProto = GetContactProto(hContact); if (pszProto == nullptr) continue; diff --git a/plugins/Quotes/src/ImportExport.cpp b/plugins/Quotes/src/ImportExport.cpp index 6836c11520..279700170e 100644 --- a/plugins/Quotes/src/ImportExport.cpp +++ b/plugins/Quotes/src/ImportExport.cpp @@ -222,7 +222,7 @@ INT_PTR Quotes_Export(WPARAM wp, LPARAM lp) } } else { - for (hContact = db_find_first(QUOTES_MODULE_NAME); hContact; hContact = db_find_next(hContact, QUOTES_MODULE_NAME)) { + for (auto &hContact : contact_iter(QUOTES_MODULE_NAME)) { CQuotesProviders::TQuotesProviderPtr pProvider = pProviders->GetContactProviderPtr(hContact); if (pProvider) { IXMLNode::TXMLNodePtr pNode = export_contact(hContact, pXmlEngine); diff --git a/plugins/Quotes/src/QuotesProviders.cpp b/plugins/Quotes/src/QuotesProviders.cpp index b097901502..ebfff01994 100644 --- a/plugins/Quotes/src/QuotesProviders.cpp +++ b/plugins/Quotes/src/QuotesProviders.cpp @@ -51,7 +51,7 @@ void CQuotesProviders::InitProviders() const WORD nCurrentVersion = 17; WORD nVersion = db_get_w(NULL, QUOTES_MODULE_NAME, LAST_RUN_VERSION, 1); - for (MCONTACT hContact = db_find_first(QUOTES_MODULE_NAME); hContact; hContact = db_find_next(hContact, QUOTES_MODULE_NAME)) { + for (auto &hContact : contact_iter(QUOTES_MODULE_NAME)) { TQuotesProviderPtr pProvider = GetContactProviderPtr(hContact); if (pProvider) { pProvider->AddContact(hContact); diff --git a/plugins/Rate/src/main.cpp b/plugins/Rate/src/main.cpp index 1f411a7bde..a5df2a30fe 100644 --- a/plugins/Rate/src/main.cpp +++ b/plugins/Rate/src/main.cpp @@ -99,7 +99,7 @@ static IconItem iconList[] = int onModulesLoaded(WPARAM, LPARAM) { // Set initial value for all contacts - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) setExtraIcon(hContact, -1, FALSE); return 0; diff --git a/plugins/RecentContacts/src/RecentContacts.cpp b/plugins/RecentContacts/src/RecentContacts.cpp index 599a166dd8..565ccee576 100644 --- a/plugins/RecentContacts/src/RecentContacts.cpp +++ b/plugins/RecentContacts/src/RecentContacts.cpp @@ -392,7 +392,7 @@ INT_PTR OnMenuCommandShowList(WPARAM, LPARAM) BYTE buf[1]; dbe.pBlob = buf; - for (MCONTACT curContact = db_find_first(); curContact != NULL; curContact = db_find_next(curContact)) { + for (auto &curContact : contact_iter()) { __time64_t curTime = GetLastUsedTimeStamp(curContact); MEVENT curEvent = db_event_last(curContact); diff --git a/plugins/SMS/src/SMS_svc.cpp b/plugins/SMS/src/SMS_svc.cpp index 1f62781b2f..99e3059127 100644 --- a/plugins/SMS/src/SMS_svc.cpp +++ b/plugins/SMS/src/SMS_svc.cpp @@ -77,7 +77,7 @@ int SendSMSMenuCommand(WPARAM wParam, LPARAM) EnableWindow(GetDlgItem(hwndSendSms, IDC_NAME), TRUE); EnableWindow(GetDlgItem(hwndSendSms, IDC_SAVENUMBER), FALSE); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { if (GetContactPhonesCount(hContact)) { SendDlgItemMessage(hwndSendSms, IDC_NAME, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetContactDisplayName(hContact, 0)); SendSMSWindowSMSContactAdd(hwndSendSms, hContact); diff --git a/plugins/SMS/src/functions.cpp b/plugins/SMS/src/functions.cpp index 3f125ac24e..0adc6aee21 100644 --- a/plugins/SMS/src/functions.cpp +++ b/plugins/SMS/src/functions.cpp @@ -183,7 +183,7 @@ MCONTACT HContactFromPhone(LPWSTR lpwszPhone, size_t dwPhoneSize) { if (lpwszPhone && dwPhoneSize) { //check not already on list - for (MCONTACT hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) if (IsContactPhone(hContact, lpwszPhone, dwPhoneSize)) return hContact; } diff --git a/plugins/SMS/src/senddlg.cpp b/plugins/SMS/src/senddlg.cpp index 40bd163a53..ed13941203 100644 --- a/plugins/SMS/src/senddlg.cpp +++ b/plugins/SMS/src/senddlg.cpp @@ -1051,7 +1051,7 @@ void SendSMSWindowFillTreeView(HWND hWnd) HWND hWndTreeView = GetDlgItem(hWnd, IDC_NUMBERSLIST); TreeView_DeleteAllItems(hWndTreeView); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HTREEITEM hParent = nullptr; LPSTR lpszProto = GetContactProto(hContact); if (lpszProto) { diff --git a/plugins/Scriver/src/msgoptions.cpp b/plugins/Scriver/src/msgoptions.cpp index 741f64191a..6dae9ab64a 100644 --- a/plugins/Scriver/src/msgoptions.cpp +++ b/plugins/Scriver/src/msgoptions.cpp @@ -828,7 +828,7 @@ static void RebuildList(HWND hwndDlg, HANDLE hItemNew, HANDLE hItemUnknown) if (hItemUnknown && db_get_b(0, SRMM_MODULE, SRMSGSET_TYPINGUNKNOWN, SRMSGDEFSET_TYPINGUNKNOWN)) SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM)hItemUnknown, 1); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem && db_get_b(hContact, SRMM_MODULE, SRMSGSET_TYPING, defType)) SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM)hItem, 1); @@ -843,7 +843,7 @@ static void SaveList(HWND hwndDlg, HANDLE hItemNew, HANDLE hItemUnknown) if (hItemUnknown) db_set_b(0, SRMM_MODULE, SRMSGSET_TYPINGUNKNOWN, (BYTE)(SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM)hItemUnknown, 0) ? 1 : 0)); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem) db_set_b(hContact, SRMM_MODULE, SRMSGSET_TYPING, (BYTE)(SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM)hItem, 0) ? 1 : 0)); diff --git a/plugins/Scriver/src/msgs.cpp b/plugins/Scriver/src/msgs.cpp index 7e0ddb8a4f..f22f60c430 100644 --- a/plugins/Scriver/src/msgs.cpp +++ b/plugins/Scriver/src/msgs.cpp @@ -248,7 +248,7 @@ static void RestoreUnreadMessageAlerts(void) { OBJLIST arEvents(10, NumericKeySortT); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { for (MEVENT hDbEvent = db_event_firstUnread(hContact); hDbEvent; hDbEvent = db_event_next(hContact, hDbEvent)) { DBEVENTINFO dbei = {}; dbei.cbBlob = 0; diff --git a/plugins/SecureIM/src/crypt_icons.cpp b/plugins/SecureIM/src/crypt_icons.cpp index 2c7eb2fd75..a428bdbefc 100644 --- a/plugins/SecureIM/src/crypt_icons.cpp +++ b/plugins/SecureIM/src/crypt_icons.cpp @@ -109,7 +109,7 @@ void RefreshContactListIcons(void) for (auto &it : arIcoList) it->hCLIcon = nullptr; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) if (isSecureProtocol(hContact)) ShowStatusIcon(hContact); } diff --git a/plugins/SecureIM/src/crypt_lists.cpp b/plugins/SecureIM/src/crypt_lists.cpp index be5f6a5e0a..9ccba72941 100644 --- a/plugins/SecureIM/src/crypt_lists.cpp +++ b/plugins/SecureIM/src/crypt_lists.cpp @@ -120,7 +120,7 @@ void loadContactList() freeContactList(); loadSupportedProtocols(); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) addContact(hContact); } diff --git a/plugins/SecureIM/src/options.cpp b/plugins/SecureIM/src/options.cpp index 3a5065d88f..0912acf37b 100644 --- a/plugins/SecureIM/src/options.cpp +++ b/plugins/SecureIM/src/options.cpp @@ -975,7 +975,7 @@ void RefreshGeneralDlg(HWND hDlg, BOOL iInit) char tmp[NAMSIZE]; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { pUinKey ptr = getUinKey(hContact); if (ptr && isSecureProtocol(hContact) && !isChatRoom(hContact)) { if (iInit) { @@ -1061,7 +1061,7 @@ void RefreshPGPDlg(HWND hDlg, BOOL iInit) char tmp[NAMSIZE]; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { pUinKey ptr = getUinKey(hContact); if (ptr && ptr->mode == MODE_PGP && isSecureProtocol(hContact) && !isChatRoom(hContact)) { LPSTR szKeyID = db_get_sa(hContact, MODULENAME, "pgp_abbr"); @@ -1121,7 +1121,7 @@ void RefreshGPGDlg(HWND hDlg, BOOL iInit) char tmp[NAMSIZE]; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { pUinKey ptr = getUinKey(hContact); if (ptr && ptr->mode == MODE_GPG && isSecureProtocol(hContact) && !isChatRoom(hContact)) { if (iInit) @@ -1174,7 +1174,7 @@ void ResetGeneralDlg(HWND hDlg) lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM; char tmp[NAMSIZE]; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { if (!isSecureProtocol(hContact) || isChatRoom(hContact)) continue; diff --git a/plugins/SeenPlugin/src/missed.cpp b/plugins/SeenPlugin/src/missed.cpp index bdce23791a..5e608c213e 100644 --- a/plugins/SeenPlugin/src/missed.cpp +++ b/plugins/SeenPlugin/src/missed.cpp @@ -42,7 +42,7 @@ int RemoveUser(int pos) int ResetMissed(void) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) db_set_b(hContact, S_MOD, "Missed", 0); memset(&mcs, 0, sizeof(mcs)); @@ -51,7 +51,7 @@ int ResetMissed(void) int CheckIfOnline(void) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) if (pcli->pfnGetContactIcon(hContact) != ICON_OFFLINE) db_set_b(hContact, S_MOD, "Missed", 2); diff --git a/plugins/SeenPlugin/src/utils.cpp b/plugins/SeenPlugin/src/utils.cpp index 203c2ed258..4a1538cd36 100644 --- a/plugins/SeenPlugin/src/utils.cpp +++ b/plugins/SeenPlugin/src/utils.cpp @@ -654,7 +654,7 @@ static void cleanThread(void *param) // I hope in 10 secons all logged-in contacts will be listed if (WaitForSingleObject(g_hShutdownEvent, 10000) == WAIT_TIMEOUT) { - for (MCONTACT hContact = db_find_first(szProto); hContact; hContact = db_find_next(hContact, szProto)) { + for (auto &hContact : contact_iter(szProto)) { WORD oldStatus = db_get_w(hContact, S_MOD, "StatusTriger", ID_STATUS_OFFLINE) | 0x8000; if (oldStatus > ID_STATUS_OFFLINE) { if (db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE) { diff --git a/plugins/Sessions/Src/Main.cpp b/plugins/Sessions/Src/Main.cpp index 303fcf3fd5..6ee67026ad 100644 --- a/plugins/Sessions/Src/Main.cpp +++ b/plugins/Sessions/Src/Main.cpp @@ -204,7 +204,7 @@ INT_PTR CALLBACK SaveSessionDlgProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM l GetDlgItemText(hdlg, IDC_LIST, szUserSessionName, _countof(szUserSessionName)); szUserSessionName[length + 1] = '\0'; if (IsDlgButtonChecked(hdlg, IDC_SELCONTACTS) && bSC) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { BYTE res = (BYTE)SendMessage(hClistControl, CLM_GETCHECKMARK, SendMessage(hClistControl, CLM_FINDCONTACT, hContact, 0), 0); if (res) { user_session_list[i] = hContact; @@ -408,7 +408,7 @@ int SaveSessionHandles(WPARAM, LPARAM lparam) return 1; int k = 0; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { if ((k = CheckForDuplicate(session_list, hContact)) != -1 && !(g_bExclHidden && !CheckContactVisibility(hContact))) { AddSessionMark(hContact, lparam, '1'); AddInSessionOrder(hContact, lparam, k, 1); @@ -528,7 +528,7 @@ int LoadSession(WPARAM, LPARAM lparam) if (session_list_recovered[0] && lparam == 256 && mode == 0) memcpy(session_list_t, session_list_recovered, sizeof(session_list_t)); else - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) if (LoadContactsFromMask(hContact, mode, lparam)) { int i = GetInSessionOrder(hContact, mode, lparam); session_list_t[i] = hContact; @@ -577,7 +577,7 @@ int LoadSession(WPARAM, LPARAM lparam) int DelUserDefSession(int ses_count) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { RemoveSessionMark(hContact, 1, ses_count); SetInSessionOrder(hContact, 1, ses_count, 0); } @@ -613,7 +613,7 @@ int DelUserDefSession(int ses_count) int DeleteAutoSession(int ses_count) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { RemoveSessionMark(hContact, 0, ses_count); SetInSessionOrder(hContact, 0, ses_count, 0); } @@ -841,7 +841,7 @@ extern "C" __declspec(dllexport) int Load(void) int i = 0; memset(session_list_recovered, 0, sizeof(session_list_recovered)); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) if (db_get_b(hContact, MODNAME, "wasInLastSession", 0)) session_list_recovered[i++] = hContact; } diff --git a/plugins/Sessions/Src/Options.cpp b/plugins/Sessions/Src/Options.cpp index cfc378ff6e..f19d90c1e1 100644 --- a/plugins/Sessions/Src/Options.cpp +++ b/plugins/Sessions/Src/Options.cpp @@ -46,7 +46,7 @@ int OpLoadSessionContacts(WPARAM, LPARAM lparam) { memset(session_list_t, 0, sizeof(session_list_t)); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { if (LoadContactsFromMask(hContact, 1, lparam)) { int i = GetInSessionOrder(hContact, 1, lparam); session_list_t[i] = hContact; @@ -314,7 +314,7 @@ static INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM l if (!hOpClistControl) EnableWindow(GetDlgItem(hdlg, IDC_DEL), TRUE); else { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) SendMessage(hOpClistControl, CLM_SETCHECKMARK, hContact, 0); for (int i = 0; session_list_t[i] > 0; i++) { @@ -361,7 +361,7 @@ static INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM l case IDC_SAVE: { int i = 0; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { BYTE res = (BYTE)SendDlgItemMessage(hdlg, IDC_EMCLIST, CLM_GETCHECKMARK, SendDlgItemMessage(hdlg, IDC_EMCLIST, CLM_FINDCONTACT, hContact, 0), 0); if (res) { diff --git a/plugins/ShellExt/src/shlcom.cpp b/plugins/ShellExt/src/shlcom.cpp index 94cce6dece..4d80f6cb10 100644 --- a/plugins/ShellExt/src/shlcom.cpp +++ b/plugins/ShellExt/src/shlcom.cpp @@ -252,7 +252,7 @@ bool ipcGetSortedContacts(THeaderIPC *ipch, int *pSlot, bool bGroupMode) TSlotInfo *pContacts = (TSlotInfo*)mir_alloc((dwContacts + 2) * sizeof(TSlotInfo)); int i = 0; int dwOnline = 0; - for (MCONTACT hContact = db_find_first(); hContact != 0; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { if (i >= dwContacts) break; @@ -342,7 +342,7 @@ bool ipcGetSortedContacts(THeaderIPC *ipch, int *pSlot, bool bGroupMode) // worker thread to clear MRU, called by the IPC bridge void __cdecl ClearMRUThread(void*) { - for (MCONTACT hContact = db_find_first(); hContact != 0; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) if (db_get_b(hContact, SHLExt_Name, SHLExt_MRU, 0) > 0) db_set_b(hContact, SHLExt_Name, SHLExt_MRU, 0); } diff --git a/plugins/SimpleStatusMsg/src/main.cpp b/plugins/SimpleStatusMsg/src/main.cpp index dafe0449b2..c1de51a2d0 100644 --- a/plugins/SimpleStatusMsg/src/main.cpp +++ b/plugins/SimpleStatusMsg/src/main.cpp @@ -1617,7 +1617,7 @@ static int OnICQStatusMsgRequest(WPARAM wParam, LPARAM lParam, LPARAM lMirParam) BOOL bContactFound = FALSE; MCONTACT hContact; - for (hContact = db_find_first(szProto); hContact; hContact = db_find_next(hContact, szProto)) { + for (auto &hContact : contact_iter()) { if (db_get_dw(hContact, szProto, "UIN", 0) == (DWORD)lParam) { bContactFound = TRUE; break; diff --git a/plugins/SmileyAdd/src/smileys.cpp b/plugins/SmileyAdd/src/smileys.cpp index 5b07d56bd4..ceeff234c1 100644 --- a/plugins/SmileyAdd/src/smileys.cpp +++ b/plugins/SmileyAdd/src/smileys.cpp @@ -748,7 +748,7 @@ void SmileyCategoryListType::DeleteAccountAsCategory(PROTOACCOUNT *acc) { CMStringW tname(_A2T(acc->szModuleName)); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { char *proto = GetContactProto(hContact); if (proto == nullptr) continue; @@ -841,7 +841,7 @@ void SmileyCategoryListType::AddAllProtocolsAsCategory(void) for (int i = 0; i < protoCount; i++) AddAccountAsCategory(accList[i], defaultFile); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) AddContactTransportAsCategory(hContact, defaultFile); CMStringW cats; diff --git a/plugins/Spamotron/src/spamotron.cpp b/plugins/Spamotron/src/spamotron.cpp index 9464ca0a32..10f4ec4dfb 100644 --- a/plugins/Spamotron/src/spamotron.cpp +++ b/plugins/Spamotron/src/spamotron.cpp @@ -484,9 +484,8 @@ void RemoveNotOnListSettings() { DBVARIANT dbv; char protoName[256] = { 0 }; - MCONTACT hContact = db_find_first(); mir_strcpy(protoName, "proto_"); - while (hContact != NULL) { + for (auto &hContact : contact_iter()) { if (db_get_s(hContact, "Protocol", "p", &dbv) == 0) { mir_strcat(protoName, dbv.pszVal); if (_getOptB(protoName, 0) != 0) { @@ -497,7 +496,6 @@ void RemoveNotOnListSettings() db_free(&dbv); } protoName[6] = 0; - hContact = db_find_next(hContact); } } diff --git a/plugins/StopSpamMod/src/utilities.cpp b/plugins/StopSpamMod/src/utilities.cpp index 535a800174..c5b3981abc 100755 --- a/plugins/StopSpamMod/src/utilities.cpp +++ b/plugins/StopSpamMod/src/utilities.cpp @@ -255,7 +255,7 @@ void __cdecl CleanProtocolTmpThread(void *param) } std::list contacts; - for (MCONTACT hContact = db_find_first(szProto); hContact; hContact = db_find_next(hContact, szProto)) + for (auto &hContact : contact_iter(szProto)) if (db_get_b(hContact, "CList", "NotOnList", 0) || (L"Not In List" == DBGetContactSettingStringPAN(hContact, "CList", "Group", L""))) contacts.push_back(hContact); @@ -285,7 +285,7 @@ void __cdecl CleanProtocolExclThread(void *param) } std::list contacts; - for (MCONTACT hContact = db_find_first(szProto); hContact; hContact = db_find_next(hContact, szProto)) + for (auto &hContact : contact_iter(szProto)) if (db_get_b(hContact, "CList", "NotOnList", 0) && db_get_b(hContact, pluginName, "Excluded", 0)) contacts.push_back(hContact); diff --git a/plugins/TabSRMM/src/container.cpp b/plugins/TabSRMM/src/container.cpp index c01dec57bb..41cfdfb025 100644 --- a/plugins/TabSRMM/src/container.cpp +++ b/plugins/TabSRMM/src/container.cpp @@ -2191,7 +2191,7 @@ void TSAPI DeleteContainer(int iIndex) db_set_ws(0, CONTAINER_KEY, szIndex, L"**free**"); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { ptrW tszValue(db_get_wsa(hContact, SRMSGMOD_T, CONTAINER_SUBKEY)); if (!mir_wstrcmp(tszValue, tszContainerName)) db_unset(hContact, SRMSGMOD_T, CONTAINER_SUBKEY); @@ -2225,7 +2225,7 @@ void TSAPI RenameContainer(int iIndex, const wchar_t *szNew) db_set_ws(0, CONTAINER_KEY, szIndex, szNew); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { ptrW tszValue(db_get_wsa(hContact, SRMSGMOD_T, CONTAINER_SUBKEY)); if (!mir_wstrcmp(tszValue, tszContainerName)) db_set_ws(hContact, SRMSGMOD_T, CONTAINER_SUBKEY, szNew); diff --git a/plugins/TabSRMM/src/globals.cpp b/plugins/TabSRMM/src/globals.cpp index ca23d4f1ed..adc81218a0 100644 --- a/plugins/TabSRMM/src/globals.cpp +++ b/plugins/TabSRMM/src/globals.cpp @@ -454,7 +454,7 @@ int CGlobals::PreshutdownSendRecv(WPARAM, LPARAM) ::TN_ModuleDeInit(); ::CloseAllContainers(); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) db_set_dw(hContact, SRMSGMOD_T, "messagecount", 0); ::SI_DeinitStatusIcons(); @@ -501,7 +501,7 @@ void CGlobals::RestoreUnreadMessageAlerts(void) { OBJLIST arEvents(10, NumericKeySortT); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { if (db_get_dw(hContact, "SendLater", "count", 0)) sendLater->addContact(hContact); diff --git a/plugins/TabSRMM/src/msgoptions.cpp b/plugins/TabSRMM/src/msgoptions.cpp index e2caa252ed..d0b5a2e5dd 100644 --- a/plugins/TabSRMM/src/msgoptions.cpp +++ b/plugins/TabSRMM/src/msgoptions.cpp @@ -881,7 +881,7 @@ class COptTypingDlg : public CDlgBase if (hItemUnknown && M.GetByte(SRMSGMOD, SRMSGSET_TYPINGUNKNOWN, SRMSGDEFSET_TYPINGUNKNOWN)) SendDlgItemMessage(m_hwnd, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM)hItemUnknown, 1); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendDlgItemMessage(m_hwnd, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem && db_get_b(hContact, SRMSGMOD, SRMSGSET_TYPING, defType)) SendDlgItemMessage(m_hwnd, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM)hItem, 1); @@ -896,7 +896,7 @@ class COptTypingDlg : public CDlgBase if (hItemUnknown) db_set_b(0, SRMSGMOD, SRMSGSET_TYPINGUNKNOWN, (BYTE)(SendDlgItemMessage(m_hwnd, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM)hItemUnknown, 0) ? 1 : 0)); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendDlgItemMessage(m_hwnd, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem) db_set_b(hContact, SRMSGMOD, SRMSGSET_TYPING, (BYTE)(SendDlgItemMessage(m_hwnd, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM)hItem, 0) ? 1 : 0)); diff --git a/plugins/TabSRMM/src/sendqueue.cpp b/plugins/TabSRMM/src/sendqueue.cpp index d3c24c0f34..43d26950e9 100644 --- a/plugins/TabSRMM/src/sendqueue.cpp +++ b/plugins/TabSRMM/src/sendqueue.cpp @@ -205,7 +205,7 @@ int SendQueue::sendQueued(CTabBaseDlg *dat, const int iEntry) size_t iSendLength = getSendLength(iEntry); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem && SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) { CContactCache *c = CContactCache::getContactCache(hContact); @@ -221,7 +221,7 @@ int SendQueue::sendQueued(CTabBaseDlg *dat, const int iEntry) return 0; } - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem && SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) { doSendLater(iEntry, nullptr, hContact, false); diff --git a/plugins/TabSRMM/src/trayicon.cpp b/plugins/TabSRMM/src/trayicon.cpp index 20bbab57f8..122266d5f2 100644 --- a/plugins/TabSRMM/src/trayicon.cpp +++ b/plugins/TabSRMM/src/trayicon.cpp @@ -287,7 +287,7 @@ void TSAPI LoadFavoritesAndRecent() if (recentEntries == nullptr) return; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { if (M.GetByte(hContact, "isFavorite", 0)) AddContactToFavorites(hContact, nullptr, nullptr, nullptr, 0, nullptr, 1, PluginConfig.g_hMenuFavorites); if ((dwRecent = M.GetDword(hContact, "isRecent", 0)) != 0 && iIndex < nen_options.wMaxRecent) { diff --git a/plugins/TipperYM/src/options.cpp b/plugins/TipperYM/src/options.cpp index 15489d189c..289b748916 100644 --- a/plugins/TipperYM/src/options.cpp +++ b/plugins/TipperYM/src/options.cpp @@ -1842,7 +1842,7 @@ INT_PTR CALLBACK DlgProcFavouriteContacts(HWND hwndDlg, UINT msg, WPARAM wParam, SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETGREYOUTFLAGS, 0, 0); SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETLEFTMARGIN, 2, 0); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem && db_get_b(hContact, MODULE, "FavouriteContact", 0)) SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM)hItem, 1); @@ -1859,7 +1859,7 @@ INT_PTR CALLBACK DlgProcFavouriteContacts(HWND hwndDlg, UINT msg, WPARAM wParam, BYTE isChecked; int count = 0; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem) { isChecked = (BYTE)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM)hItem, 0); diff --git a/plugins/TipperYM/src/popwin.cpp b/plugins/TipperYM/src/popwin.cpp index 7c97954284..533c1abee9 100644 --- a/plugins/TipperYM/src/popwin.cpp +++ b/plugins/TipperYM/src/popwin.cpp @@ -1470,7 +1470,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa if (dwItems & TRAYTIP_NUMCONTACTS) { int iCount = 0, iCountOnline = 0; - for (MCONTACT hContact = db_find_first(pa->szModuleName); hContact; hContact = db_find_next(hContact, pa->szModuleName)) { + for (auto &hContact : contact_iter(pa->szModuleName)) { if (db_get_w(hContact, pa->szModuleName, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) iCountOnline++; iCount++; @@ -1588,7 +1588,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa bool bTitlePainted = false; int iCount = 0, iCountOnline = 0; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { if (db_get_b(hContact, MODULE, "FavouriteContact", 0)) { char *proto = GetContactProto(hContact); if (proto == nullptr) diff --git a/plugins/TooltipNotify/src/TooltipNotify.cpp b/plugins/TooltipNotify/src/TooltipNotify.cpp index d68ba585f6..74b60f1e25 100644 --- a/plugins/TooltipNotify/src/TooltipNotify.cpp +++ b/plugins/TooltipNotify/src/TooltipNotify.cpp @@ -719,7 +719,7 @@ void CTooltipNotify::LoadList(HWND hwndDlg, HANDLE hItemNew, HANDLE hItemUnknown if (hItemUnknown && !m_sOptions.bIgnoreUnknown) SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM)hItemUnknown, 1); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem && !db_get_b(hContact, MODULENAME, CONTACT_IGNORE_TTNOTIFY, m_sOptions.bIgnoreNew)) SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM)hItem, 1); @@ -734,7 +734,7 @@ void CTooltipNotify::SaveList(HWND hwndDlg, HANDLE hItemNew, HANDLE hItemUnknown if (hItemUnknown) m_sOptions.bIgnoreUnknown = (BYTE)(SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM)hItemUnknown, 0) ? 0 : 1); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem) { BYTE bChecked = (BYTE)(SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM)hItem, 0)); diff --git a/plugins/UserInfoEx/src/dlg_anniversarylist.cpp b/plugins/UserInfoEx/src/dlg_anniversarylist.cpp index 237f94c7fd..9ef92feeab 100644 --- a/plugins/UserInfoEx/src/dlg_anniversarylist.cpp +++ b/plugins/UserInfoEx/src/dlg_anniversarylist.cpp @@ -741,7 +741,7 @@ class CAnnivList mtNow.GetLocalTime(); // insert the items into the list - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { // ignore meta subcontacts here, as they are not interesting. if (!db_mc_isSub(hContact)) { // filter protocol diff --git a/plugins/UserInfoEx/src/dlg_propsheet.cpp b/plugins/UserInfoEx/src/dlg_propsheet.cpp index 618cf63c4f..b5142bdcd4 100644 --- a/plugins/UserInfoEx/src/dlg_propsheet.cpp +++ b/plugins/UserInfoEx/src/dlg_propsheet.cpp @@ -543,7 +543,6 @@ void DlgContactInfoInitTreeIcons() if (!(bInitIcons & INIT_ICONS_ALL)) { CPsHdr psh; POINT metrics = {0}; - int i = 0; psh._dwFlags = PSTVF_INITICONS; @@ -566,7 +565,7 @@ void DlgContactInfoInitTreeIcons() PROTOACCOUNT **pd; int ProtoCount = 0; Proto_EnumAccounts(&ProtoCount, &pd); - for (i = 0; i < ProtoCount; i++) { + for (int i = 0; i < ProtoCount; i++) { // enumerate all contacts for (psh._hContact = db_find_first(); psh._hContact != NULL; psh._hContact = db_find_next(psh._hContact)) { // compare contact's protocol to the current one, to add diff --git a/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp b/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp index b7311f6874..77fdb16776 100644 --- a/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp +++ b/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp @@ -499,7 +499,7 @@ BYTE CExImContactBase::isHandle(MCONTACT hContact) **/ MCONTACT CExImContactBase::findHandle() { - for (MCONTACT hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { if (isHandle(hContact)) { _hContact = hContact; _isNewContact = FALSE; diff --git a/plugins/UserInfoEx/src/psp_options.cpp b/plugins/UserInfoEx/src/psp_options.cpp index e4481391ad..cd8d14ec6e 100644 --- a/plugins/UserInfoEx/src/psp_options.cpp +++ b/plugins/UserInfoEx/src/psp_options.cpp @@ -466,7 +466,7 @@ static INT_PTR CALLBACK DlgProc_AdvancedOpts(HWND hDlg, UINT uMsg, WPARAM wParam DB::Module::Delete(NULL, USERINFO"ExW"); // delete old contactsettings - for (hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { db_unset(hContact, USERINFO, "PListColWidth0"); db_unset(hContact, USERINFO, "PListColWidth1"); db_unset(hContact, USERINFO, "PListColWidth2"); @@ -669,7 +669,7 @@ static INT_PTR CALLBACK DlgProc_ReminderOpts(HWND hDlg, UINT uMsg, WPARAM wParam // walk through all the contacts stored in the DB MAnnivDate mdb; - for (MCONTACT hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) mdb.DBMoveBirthDate(hContact, bOld, bNew); } diff --git a/plugins/UserInfoEx/src/svc_avatar.cpp b/plugins/UserInfoEx/src/svc_avatar.cpp index cd553e6e1d..0ed9bd5b12 100644 --- a/plugins/UserInfoEx/src/svc_avatar.cpp +++ b/plugins/UserInfoEx/src/svc_avatar.cpp @@ -102,7 +102,7 @@ namespace NServices if (bEnable && !ghChangedHook) { // walk through all the contacts stored in the DB - for (MCONTACT hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { // don't set if avatar is locked! if (!db_get_b(hContact, "ContactPhoto", "Locked", 0)) { BYTE bInvalidAvatar = TRUE; @@ -144,7 +144,7 @@ namespace NServices ghChangedHook = nullptr; // walk through all the contacts stored in the DB - for (MCONTACT hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) DeleteAvatar(hContact); } } diff --git a/plugins/UserInfoEx/src/svc_refreshci.cpp b/plugins/UserInfoEx/src/svc_refreshci.cpp index 5b6b65987f..ac280af39a 100644 --- a/plugins/UserInfoEx/src/svc_refreshci.cpp +++ b/plugins/UserInfoEx/src/svc_refreshci.cpp @@ -692,7 +692,7 @@ public: { int iWait = 100; - for (MCONTACT hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) if (QueueAddRefreshContact(hContact, iWait)) iWait += 5000; diff --git a/plugins/UserInfoEx/src/svc_reminder.cpp b/plugins/UserInfoEx/src/svc_reminder.cpp index 0b50dfd8ed..4c85441be5 100644 --- a/plugins/UserInfoEx/src/svc_reminder.cpp +++ b/plugins/UserInfoEx/src/svc_reminder.cpp @@ -564,7 +564,7 @@ void SvcReminderCheckAll(const ENotify notify) // walk through all the contacts stored in the DB CEvent evt; WORD a1 = 0; - for (MCONTACT hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) CheckContact(hContact, now, evt, notify != NOTIFY_CLIST, &a1); if (notify != NOTIFY_CLIST) { @@ -727,7 +727,7 @@ static INT_PTR BackupBirthdayService(WPARAM hContact, LPARAM lParam) WORD a1 = 0; //walk through all the contacts stored in the DB - for (hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) if (!db_mc_isSub(hContact) && !mdb.DBGetBirthDate(hContact)) mdb.BackupBirthday(hContact, nullptr, TRUE, &a1); } @@ -858,7 +858,7 @@ void SvcReminderEnable(BYTE bEnable) UpdateTimer(TRUE); } else { // Reminder is off - for (MCONTACT hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) NotifyWithExtraIcon(hContact, CEvent()); gRemindOpts.RemindState = REMIND_OFF; diff --git a/plugins/Variables/src/contact.cpp b/plugins/Variables/src/contact.cpp index 8574cea41f..9c8e51ecaa 100644 --- a/plugins/Variables/src/contact.cpp +++ b/plugins/Variables/src/contact.cpp @@ -197,7 +197,7 @@ MCONTACT getContactFromString(const wchar_t *tszContact, DWORD dwFlags, int nMat MCONTACT hContact; LIST arResults(1); - for (hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { // <_HANDLE_:hContact> tmp.Format(L"<%s:%d>", _A2W(PROTOID_HANDLE), hContact); bool bMatch = (tmp == tszContact); diff --git a/plugins/Variables/src/parse_miranda.cpp b/plugins/Variables/src/parse_miranda.cpp index e6280737d5..8eb429ba81 100644 --- a/plugins/Variables/src/parse_miranda.cpp +++ b/plugins/Variables/src/parse_miranda.cpp @@ -439,7 +439,7 @@ static MEVENT findDbEvent(MCONTACT hContact, MEVENT hDbEvent, int flags) DBEVENTINFO dbe = {}; if (flags & DBE_FIRST) { - for (MCONTACT hSearchContact = db_find_first(); hSearchContact; hSearchContact = db_find_next(hSearchContact)) { + for (auto &hSearchContact : contact_iter()) { hSearchEvent = findDbEvent(hSearchContact, NULL, flags); dbe.cbBlob = 0; if (!db_event_get(hSearchEvent, &dbe)) { @@ -452,7 +452,7 @@ static MEVENT findDbEvent(MCONTACT hContact, MEVENT hDbEvent, int flags) hDbEvent = hMatchEvent; } else if (flags & DBE_LAST) { - for (MCONTACT hSearchContact = db_find_first(); hSearchContact; hSearchContact = db_find_next(hSearchContact)) { + for (auto &hSearchContact : contact_iter()) { hSearchEvent = findDbEvent(hSearchContact, NULL, flags); dbe.cbBlob = 0; if (!db_event_get(hSearchEvent, &dbe)) { @@ -468,7 +468,7 @@ static MEVENT findDbEvent(MCONTACT hContact, MEVENT hDbEvent, int flags) dbe.cbBlob = 0; if (!db_event_get(hDbEvent, &dbe)) { priorTimestamp = dbe.timestamp; - for (MCONTACT hSearchContact = db_find_first(); hSearchContact; hSearchContact = db_find_next(hSearchContact)) { + for (auto &hSearchContact : contact_iter()) { hSearchEvent = findDbEvent(hSearchContact, hDbEvent, flags); dbe.cbBlob = 0; if (!db_event_get(hSearchEvent, &dbe)) { @@ -484,7 +484,7 @@ static MEVENT findDbEvent(MCONTACT hContact, MEVENT hDbEvent, int flags) else if (flags & DBE_PREV) { if (!db_event_get(hDbEvent, &dbe)) { priorTimestamp = dbe.timestamp; - for (MCONTACT hSearchContact = db_find_first(); hSearchContact; hSearchContact = db_find_next(hSearchContact)) { + for (auto &hSearchContact : contact_iter()) { hSearchEvent = findDbEvent(hSearchContact, hDbEvent, flags); dbe.cbBlob = 0; if (!db_event_get(hSearchEvent, &dbe)) { diff --git a/plugins/Weather/src/weather_addstn.cpp b/plugins/Weather/src/weather_addstn.cpp index 0393364663..87825b72a5 100644 --- a/plugins/Weather/src/weather_addstn.cpp +++ b/plugins/Weather/src/weather_addstn.cpp @@ -39,7 +39,7 @@ INT_PTR WeatherAddToList(WPARAM, LPARAM lParam) return 0; // search for existing contact - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { // check if it is a weather contact if (IsMyContact(hContact)) { DBVARIANT dbv; diff --git a/plugins/Weather/src/weather_contacts.cpp b/plugins/Weather/src/weather_contacts.cpp index 17a2708092..647e855e99 100644 --- a/plugins/Weather/src/weather_contacts.cpp +++ b/plugins/Weather/src/weather_contacts.cpp @@ -444,7 +444,7 @@ int ContactDeleted(WPARAM wParam, LPARAM) // now the default station is deleted, try to get a new one // start looking for other weather stations - for (MCONTACT hContact = db_find_first(WEATHERPROTONAME); hContact; hContact = db_find_next(hContact, WEATHERPROTONAME)) { + for (auto &hContact : contact_iter(WEATHERPROTONAME)) { tszID = db_get_wsa(hContact, WEATHERPROTONAME, "ID"); if (tszID == NULL) continue; diff --git a/plugins/Weather/src/weather_data.cpp b/plugins/Weather/src/weather_data.cpp index 28fa9a622d..90a8a05c0a 100644 --- a/plugins/Weather/src/weather_data.cpp +++ b/plugins/Weather/src/weather_data.cpp @@ -112,7 +112,7 @@ void EraseAllInfo() MCONTACT LastContact = NULL; DBVARIANT dbv; // loop through all contacts - for (MCONTACT hContact = db_find_first(WEATHERPROTONAME); hContact; hContact = db_find_next(hContact, WEATHERPROTONAME)) { + for (auto &hContact : contact_iter(WEATHERPROTONAME)) { db_set_w(hContact, WEATHERPROTONAME, "Status", ID_STATUS_OFFLINE); db_set_w(hContact, WEATHERPROTONAME, "StatusIcon", ID_STATUS_OFFLINE); db_unset(hContact, "CList", "MyHandle"); diff --git a/plugins/Weather/src/weather_mwin.cpp b/plugins/Weather/src/weather_mwin.cpp index c7377821ef..c219c2a9ca 100644 --- a/plugins/Weather/src/weather_mwin.cpp +++ b/plugins/Weather/src/weather_mwin.cpp @@ -348,7 +348,7 @@ void InitMwin(void) mir_strcpy(fontid.prefix, "fnt1"); Font_RegisterW(&fontid); - for (MCONTACT hContact = db_find_first(WEATHERPROTONAME); hContact; hContact = db_find_next(hContact, WEATHERPROTONAME)) + for (auto &hContact : contact_iter(WEATHERPROTONAME)) if (db_get_dw(hContact, WEATHERPROTONAME, "mwin", 0)) addWindow(hContact); @@ -357,7 +357,7 @@ void InitMwin(void) void DestroyMwin(void) { - for (MCONTACT hContact = db_find_first(WEATHERPROTONAME); hContact; hContact = db_find_next(hContact, WEATHERPROTONAME)) { + for (auto &hContact : contact_iter(WEATHERPROTONAME)) { DWORD frameId = db_get_dw(hContact, WEATHERPROTONAME, "mwin", 0); if (frameId) CallService(MS_CLIST_FRAMES_REMOVEFRAME, frameId, 0); diff --git a/plugins/Weather/src/weather_update.cpp b/plugins/Weather/src/weather_update.cpp index 07e69e5b5b..66feef7258 100644 --- a/plugins/Weather/src/weather_update.cpp +++ b/plugins/Weather/src/weather_update.cpp @@ -307,7 +307,7 @@ static void UpdateThreadProc(void *) void UpdateAll(BOOL AutoUpdate, BOOL RemoveData) { // add all weather contact to the update queue list - for (MCONTACT hContact = db_find_first(WEATHERPROTONAME); hContact; hContact = db_find_next(hContact, WEATHERPROTONAME)) + for (auto &hContact : contact_iter(WEATHERPROTONAME)) if (!db_get_b(hContact, WEATHERPROTONAME, "AutoUpdate", FALSE) || !AutoUpdate) { if (RemoveData) DBDataManage(hContact, WDBM_REMOVE, 0, 0); diff --git a/plugins/WebView/src/main.cpp b/plugins/WebView/src/main.cpp index 3ba57dd526..3053895860 100644 --- a/plugins/WebView/src/main.cpp +++ b/plugins/WebView/src/main.cpp @@ -70,7 +70,7 @@ void ChangeContactStatus(int con_stat) if (con_stat == 3) status_code = ID_STATUS_NA; - for (MCONTACT hContact = db_find_first(MODULENAME); hContact != NULL; hContact = db_find_next(hContact, MODULENAME)) + for (auto &hContact : contact_iter(MODULENAME)) db_set_w(hContact, MODULENAME, "Status", status_code); } diff --git a/plugins/WebView/src/webview.cpp b/plugins/WebView/src/webview.cpp index 9c77b5e6af..f15977bb1d 100644 --- a/plugins/WebView/src/webview.cpp +++ b/plugins/WebView/src/webview.cpp @@ -94,7 +94,7 @@ void FillFontListThread(void *param) /*****************************************************************************/ void TxtclrLoop() { - for (MCONTACT hContact = db_find_first(MODULENAME); hContact != NULL; hContact = db_find_next(hContact, MODULENAME)) { + for (auto &hContact : contact_iter(MODULENAME)) { HWND hwndDlg = WindowList_Find(hWindowList, hContact); SetDlgItemText(hwndDlg, IDC_DATA, L""); InvalidateRect(hwndDlg, nullptr, 1); @@ -104,7 +104,7 @@ void TxtclrLoop() /*****************************************************************************/ void BGclrLoop() { - for (MCONTACT hContact = db_find_first(MODULENAME); hContact != NULL; hContact = db_find_next(hContact, MODULENAME)) { + for (auto &hContact : contact_iter(MODULENAME)) { HWND hwndDlg = (WindowList_Find(hWindowList, hContact)); SetDlgItemText(hwndDlg, IDC_DATA, L""); SendDlgItemMessage(hwndDlg, IDC_DATA, EM_SETBKGNDCOLOR, 0, BackgoundClr); @@ -118,7 +118,7 @@ void StartUpdate(void*) StartUpDelay = 1; Sleep(((db_get_dw(NULL, MODULENAME, START_DELAY_KEY, 0)) * SECOND)); - for (MCONTACT hContact = db_find_first(MODULENAME); hContact != NULL; hContact = db_find_next(hContact, MODULENAME)) + for (auto &hContact : contact_iter(MODULENAME)) GetData((void*)hContact); StartUpDelay = 0; @@ -128,7 +128,7 @@ void StartUpdate(void*) void ContactLoop(void*) { if (StartUpDelay == 0) { - for (MCONTACT hContact = db_find_first(MODULENAME); hContact != NULL; hContact = db_find_next(hContact, MODULENAME)) { + for (auto &hContact : contact_iter(MODULENAME)) { GetData((void*)hContact); Sleep(10); // avoid 100% CPU } diff --git a/plugins/WebView/src/webview_datawnd.cpp b/plugins/WebView/src/webview_datawnd.cpp index bbbed64265..b467e396f1 100644 --- a/plugins/WebView/src/webview_datawnd.cpp +++ b/plugins/WebView/src/webview_datawnd.cpp @@ -128,7 +128,7 @@ static MCONTACT FindContactByUrl(HWND hwndDlg) GetDlgItemText(hwndDlg, IDC_OPEN_URL, urltext, _countof(urltext)); GetWindowText(hwndDlg, titlebartxt, _countof(titlebartxt)); - for (MCONTACT hContact = db_find_first(MODULENAME); hContact != NULL; hContact = db_find_next(hContact, MODULENAME)) { + for (auto &hContact : contact_iter(MODULENAME)) { ptrW db1( db_get_wsa(hContact, MODULENAME, URL_KEY)); ptrW db2( db_get_wsa(hContact, MODULENAME, PRESERVE_NAME_KEY)); diff --git a/plugins/WebView/src/webview_services.cpp b/plugins/WebView/src/webview_services.cpp index 83c6fde0ae..585b85fe77 100644 --- a/plugins/WebView/src/webview_services.cpp +++ b/plugins/WebView/src/webview_services.cpp @@ -250,7 +250,7 @@ INT_PTR SetStatus(WPARAM wParam, LPARAM) // Make sure no contact has offline status for any reason on first time run if ( db_get_b(NULL, MODULENAME, "FirstTime", 100) == 100) { - for (MCONTACT hContact = db_find_first(MODULENAME); hContact != NULL; hContact = db_find_next(hContact, MODULENAME)) + for (auto &hContact : contact_iter(MODULENAME)) db_set_w(hContact, MODULENAME, "Status", ID_STATUS_ONLINE); db_set_b(NULL, MODULENAME, "FirstTime", 1); @@ -332,7 +332,6 @@ INT_PTR AddToList(WPARAM, LPARAM lParam) { PROTOSEARCHRESULT *psr = (PROTOSEARCHRESULT *) lParam; DBVARIANT dbv; - MCONTACT hContact; int sameurl = 0; int samename = 0; @@ -346,7 +345,7 @@ INT_PTR AddToList(WPARAM, LPARAM lParam) if (psr->cbSize != sizeof(PROTOSEARCHRESULT)) return NULL; // search for existing contact - for (hContact = db_find_first(MODULENAME); hContact != NULL; hContact = db_find_next(hContact, MODULENAME)) { + for (auto &hContact : contact_iter(MODULENAME)) { // check ID to see if the contact already exist in the database if (db_get_ws(hContact, MODULENAME, "URL", &dbv)) continue; @@ -363,7 +362,7 @@ INT_PTR AddToList(WPARAM, LPARAM lParam) db_free(&dbv); } - hContact = db_add_contact(); + MCONTACT hContact = db_add_contact(); Proto_AddToContact(hContact, MODULENAME); /////////write to db @@ -399,7 +398,7 @@ INT_PTR AddToList(WPARAM, LPARAM lParam) wchar_t *Nend = wcschr(Newnick, '.'); if (Nend) *Nend = '\0'; - for (MCONTACT hContact2 = db_find_first(MODULENAME); hContact2 != NULL; hContact2 = db_find_next(hContact2, MODULENAME)) { + for (auto &hContact2 : contact_iter(MODULENAME)) { if (!db_get_ws(hContact2, MODULENAME, PRESERVE_NAME_KEY, &dbv)) { if (!mir_wstrcmpi(Newnick, dbv.ptszVal)) { // remove the flag for not on list and hidden, thus make the @@ -457,6 +456,6 @@ INT_PTR GetInfo(WPARAM, LPARAM) /*****************************************************************************/ void AckFunc(void*) { - for (MCONTACT hContact = db_find_first(MODULENAME); hContact != NULL; hContact = db_find_next(hContact, MODULENAME)) + for (auto &hContact : contact_iter(MODULENAME)) ProtoBroadcastAck(MODULENAME, hContact, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, (HANDLE)1, 0); } diff --git a/plugins/WhenWasIt/src/dlg_handlers.cpp b/plugins/WhenWasIt/src/dlg_handlers.cpp index c1d45c271d..1a98e5c4b3 100644 --- a/plugins/WhenWasIt/src/dlg_handlers.cpp +++ b/plugins/WhenWasIt/src/dlg_handlers.cpp @@ -704,7 +704,7 @@ int LoadBirthdays(HWND hWnd, int bShowAll) ListView_DeleteAllItems(hList); int count = 0; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) count = UpdateBirthdayEntry(hList, hContact, count, bShowAll, commonData.cShowAgeMode, 1); SetBirthdaysCount(hWnd); diff --git a/plugins/WhenWasIt/src/notifiers.cpp b/plugins/WhenWasIt/src/notifiers.cpp index ac16710c23..2f1e3e80ff 100644 --- a/plugins/WhenWasIt/src/notifiers.cpp +++ b/plugins/WhenWasIt/src/notifiers.cpp @@ -205,7 +205,7 @@ int SoundNotifyBirthday(int dtb) //called with oldClistIcon != -1 from dlg_handlers whtn the extra icon slot changes. int RefreshAllContactListIcons(int oldClistIcon) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { if (oldClistIcon != -1) ExtraIcon_Clear(hWWIExtraIcons, hContact); diff --git a/plugins/WhenWasIt/src/services.cpp b/plugins/WhenWasIt/src/services.cpp index 4de81db610..55a31d50af 100644 --- a/plugins/WhenWasIt/src/services.cpp +++ b/plugins/WhenWasIt/src/services.cpp @@ -299,7 +299,7 @@ int DoExport(wchar_t *fileName) fwprintf(fout, L"%c%s", COMMENT_CHAR, TranslateT("Warning! Please do not mix Unicode and Ansi exported birthday files. You should use the same version (Ansi/Unicode) of WhenWasIt that was used to export the info.\n")); fwprintf(fout, L"%c%s", COMMENT_CHAR, TranslateT("This file was exported with a Unicode version of WhenWasIt. Please only use a Unicode version of the plugin to import the birthdays.\n")); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { int year, month, day; GetContactDOB(hContact, year, month, day); if (IsDOBValid(year, month, day)) { diff --git a/plugins/WhenWasIt/src/utils.cpp b/plugins/WhenWasIt/src/utils.cpp index d2856f94a4..b44fbdc384 100644 --- a/plugins/WhenWasIt/src/utils.cpp +++ b/plugins/WhenWasIt/src/utils.cpp @@ -151,7 +151,7 @@ wchar_t* GetContactID(MCONTACT hContact, char *szProto) MCONTACT GetContactFromID(wchar_t *szID, char *szProto) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { char *m_szProto = GetContactProto(hContact); wchar_t *szHandle = GetContactID(hContact, szProto); if (szHandle) { diff --git a/plugins/WinterSpeak/src/ConfigDatabase.cpp b/plugins/WinterSpeak/src/ConfigDatabase.cpp index a67506ad8e..237ec202b8 100644 --- a/plugins/WinterSpeak/src/ConfigDatabase.cpp +++ b/plugins/WinterSpeak/src/ConfigDatabase.cpp @@ -89,12 +89,9 @@ void ConfigDatabase::load() m_welcome_msg = DBGetContactSettingString(SPEAK, WELCOME_MSG, L"Welcome to Miranda"); // iterate through all the users and add them to the list if active - MCONTACT contact = db_find_first(); - while (NULL != contact) { + for (auto &contact : contact_iter()) { m_active_users[contact].status = (db_get_b(contact, SPEAK, ACTIVE_STATE, true) != 0); m_active_users[contact].message = (db_get_b(contact, SPEAK, ACTIVE_MSG, true) != 0); - - contact = db_find_next(contact); } // load unknown users setting diff --git a/plugins/WinterSpeak/src/DialogConfigActive.cpp b/plugins/WinterSpeak/src/DialogConfigActive.cpp index 78f798bfcc..65f59b26a4 100644 --- a/plugins/WinterSpeak/src/DialogConfigActive.cpp +++ b/plugins/WinterSpeak/src/DialogConfigActive.cpp @@ -325,7 +325,7 @@ void DialogConfigActive::save(HWND window) m_db.setActiveFlag(ConfigDatabase::ActiveFlag_FreeForChat, (IsDlgButtonChecked(window, IDC_ACTIVE_FREEFORCHAT) != 0)); m_db.setActiveFlag(ConfigDatabase::ActiveFlag_Invisible, (IsDlgButtonChecked(window, IDC_ACTIVE_INVISIBLE) != 0)); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendDlgItemMessage(window, IDC_ACTIVE_USERS, CLM_FINDCONTACT, hContact, 0); if (hItem) SaveItemMask(GetDlgItem(window, IDC_ACTIVE_USERS), hContact, hItem); diff --git a/plugins/XSoundNotify/src/options.cpp b/plugins/XSoundNotify/src/options.cpp index 031729c561..f84c355f1d 100644 --- a/plugins/XSoundNotify/src/options.cpp +++ b/plugins/XSoundNotify/src/options.cpp @@ -51,7 +51,7 @@ static INT_PTR CALLBACK OptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l PROTOACCOUNT *pa = (PROTOACCOUNT *)SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_PROTO, CB_GETITEMDATA, cursel, 0); SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_SETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_ADDSTRING, 0, (LPARAM)TranslateT("All contacts")), cursel); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { char *szUniqueId = nullptr; if (db_get_b(hContact, pa->szModuleName, "ChatRoom", 0)) szUniqueId = "ChatRoomID"; diff --git a/plugins/YAMN/src/proto/pop3/pop3comm.cpp b/plugins/YAMN/src/proto/pop3/pop3comm.cpp index 71b34d6a27..280244d8a1 100644 --- a/plugins/YAMN/src/proto/pop3/pop3comm.cpp +++ b/plugins/YAMN/src/proto/pop3/pop3comm.cpp @@ -283,7 +283,7 @@ int RegisterPOP3Plugin(WPARAM, LPARAM) for (Finder = POP3Plugin->FirstAccount; Finder != nullptr; Finder = Finder->Next) { Finder->hContact = NULL; - for (MCONTACT hContact = db_find_first(YAMN_DBMODULE); hContact; hContact = db_find_next(hContact, YAMN_DBMODULE)) { + for (auto &hContact : contact_iter(YAMN_DBMODULE)) { if (!db_get_s(hContact, YAMN_DBMODULE, "Id", &dbv)) { if (mir_strcmp(dbv.pszVal, Finder->Name) == 0) { Finder->hContact = hContact; diff --git a/plugins/YAPP/src/options.cpp b/plugins/YAPP/src/options.cpp index 10da330778..5fd2230882 100644 --- a/plugins/YAPP/src/options.cpp +++ b/plugins/YAPP/src/options.cpp @@ -99,7 +99,7 @@ void ShowExamplePopups() pd.ptzText = TranslateT("Thequickbrownfoxjumpedoverthelazydog."); ShowPopup(pd); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { if (options.av_layout != PAV_NONE && ServiceExists(MS_AV_DRAWAVATAR)) { AVATARCACHEENTRY *ace = (AVATARCACHEENTRY *)CallService(MS_AV_GETAVATARBITMAP, hContact, 0); if (ace && (ace->dwFlags & AVS_BITMAP_VALID)) { diff --git a/plugins/YARelay/src/options.cpp b/plugins/YARelay/src/options.cpp index f10bfcb0e3..fe5d3bdeb1 100644 --- a/plugins/YARelay/src/options.cpp +++ b/plugins/YARelay/src/options.cpp @@ -50,7 +50,6 @@ static void OptionsFrameEnableControls(HWND hwndDlg) */ static INT_PTR CALLBACK OptionsFrameProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - MCONTACT hContact; int idx; switch (uMsg) { case WM_INITDIALOG: @@ -68,7 +67,7 @@ static INT_PTR CALLBACK OptionsFrameProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, SendDlgItemMessage(hwndDlg, IDC_COMBO_TO, CB_SETITEMDATA, (WPARAM)idx, 0); SendDlgItemMessage(hwndDlg, IDC_COMBO_TO, CB_SETCURSEL, (WPARAM)idx, 0); - for (hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { wchar_t *ptszNick = pcli->pfnGetContactDisplayName(hContact, 0); if (ptszNick){ idx = SendDlgItemMessage(hwndDlg, IDC_COMBO_TO, CB_ADDSTRING, 0, (LPARAM)ptszNick); -- cgit v1.2.3