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 --- include/m_database.h | 31 + include/m_protoint.h | 2 + libs/win32/mir_app.lib | Bin 130624 -> 131034 bytes libs/win64/mir_app.lib | Bin 126128 -> 126544 bytes 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 +- protocols/Discord/src/proto.cpp | 2 +- protocols/EmLanProto/src/mlan.cpp | 4 +- protocols/FacebookRM/src/chat.cpp | 2 +- protocols/FacebookRM/src/contacts.cpp | 6 +- protocols/FacebookRM/src/process.cpp | 2 +- protocols/Gadu-Gadu/src/core.cpp | 8 +- protocols/Gadu-Gadu/src/groupchat.cpp | 6 +- protocols/Gadu-Gadu/src/import.cpp | 2 +- protocols/ICQCorp/src/protocol.cpp | 2 +- protocols/IRCG/src/clist.cpp | 4 +- protocols/IRCG/src/commandmonitor.cpp | 2 +- protocols/IcqOscarJ/src/icq_infoupdate.cpp | 2 +- protocols/IcqOscarJ/src/icq_proto.cpp | 2 +- protocols/IcqOscarJ/src/icq_server.cpp | 2 +- protocols/IcqOscarJ/src/icq_servlist.cpp | 17 +- protocols/IcqOscarJ/src/icq_uploadui.cpp | 14 +- protocols/IcqOscarJ/src/utilities.cpp | 37 +- protocols/JabberG/src/jabber_chat.cpp | 4 +- protocols/JabberG/src/jabber_icolib.cpp | 2 +- protocols/JabberG/src/jabber_list.cpp | 2 +- protocols/JabberG/src/jabber_opt.cpp | 2 +- protocols/JabberG/src/jabber_privacy.cpp | 8 +- protocols/JabberG/src/jabber_proto.cpp | 2 +- protocols/JabberG/src/jabber_rc.cpp | 4 +- protocols/JabberG/src/jabber_thread.cpp | 2 +- protocols/MRA/src/MraProto.cpp | 4 +- protocols/MRA/src/Mra_functions.cpp | 2 +- protocols/MRA/src/Mra_menus.cpp | 6 +- protocols/MRA/src/Mra_proto.cpp | 4 +- protocols/MSN/src/msn_chat.cpp | 3 +- protocols/MSN/src/msn_contact.cpp | 6 +- protocols/MSN/src/msn_misc.cpp | 5 +- protocols/MSN/src/msn_proto.cpp | 2 +- protocols/MinecraftDynmap/src/chat.cpp | 2 +- protocols/Omegle/src/chat.cpp | 2 +- protocols/Sametime/src/sametime.cpp | 2 +- protocols/Sametime/src/session_announce_win.cpp | 2 +- protocols/Sametime/src/userlist.cpp | 7 +- protocols/SkypeWeb/src/skype_contacts.cpp | 9 +- protocols/SkypeWeb/src/skype_dialogs.cpp | 6 +- protocols/SkypeWeb/src/skype_login.cpp | 2 +- protocols/Steam/src/steam_contacts.cpp | 6 +- protocols/Tox/src/tox_avatars.cpp | 4 +- protocols/Tox/src/tox_contacts.cpp | 2 +- protocols/Twitter/src/chat.cpp | 2 +- protocols/Twitter/src/contacts.cpp | 2 +- protocols/VKontakte/src/misc.cpp | 6 +- protocols/VKontakte/src/vk_dialogs.cpp | 6 +- protocols/VKontakte/src/vk_history.cpp | 2 +- protocols/VKontakte/src/vk_thread.cpp | 6 +- src/core/stdfile/src/file.cpp | 2 +- src/core/stdmsg/src/msgoptions.cpp | 4 +- src/core/stdmsg/src/msgs.cpp | 2 +- src/mir_app/src/DefaultExtraIcons.cpp | 2 +- src/mir_app/src/ExtraIcon.cpp | 2 +- src/mir_app/src/chat_clist.cpp | 6 +- src/mir_app/src/clc.cpp | 12 +- src/mir_app/src/clcitems.cpp | 4 +- src/mir_app/src/clistgroups.cpp | 4 +- src/mir_app/src/contact.cpp | 2 +- src/mir_app/src/ignore.cpp | 4 +- src/mir_app/src/meta_addto.cpp | 2 +- src/mir_app/src/meta_main.cpp | 2 +- src/mir_app/src/meta_utils.cpp | 8 +- src/mir_app/src/mir_app.def | 1 + src/mir_app/src/mir_app64.def | 1 + src/mir_app/src/options_ei.cpp | 2 +- src/mir_app/src/proto_utils.cpp | 2 +- src/mir_app/src/visibility.cpp | 4 +- 201 files changed, 723 insertions(+), 816 deletions(-) diff --git a/include/m_database.h b/include/m_database.h index 41ce36bef5..bfab8294c5 100644 --- a/include/m_database.h +++ b/include/m_database.h @@ -227,6 +227,37 @@ EXTERN_C MIR_CORE_DLL(MCONTACT) db_find_next(MCONTACT hContact, const char *szPr EXTERN_C MIR_CORE_DLL(MCONTACT) db_find_next(MCONTACT hContact, const char *szProto); #endif +#if defined(__cplusplus) +class contact_iter +{ + const char *m_szModule; + +public: + contact_iter(const char *m = nullptr) : + m_szModule(m) + {} + + class iterator + { + MCONTACT hContact; + const char *m_szModule; + + public: + __inline iterator(const char *_m, MCONTACT _h) : + hContact(_h), + m_szModule(_m) + {} + + __inline iterator operator++() { hContact = ::db_find_next(hContact, m_szModule); return *this; } + __inline bool operator!=(const iterator &p) { return hContact != p.hContact; } + __inline operator const MCONTACT*() const { return &hContact; } + }; + + __inline iterator begin() const { return iterator(m_szModule, ::db_find_first(m_szModule)); } + __inline iterator end() const { return iterator(m_szModule, 0); } +}; +#endif + ///////////////////////////////////////////////////////////////////////////////////////// // Database events diff --git a/include/m_protoint.h b/include/m_protoint.h index 5a7e115a74..e9477ce530 100644 --- a/include/m_protoint.h +++ b/include/m_protoint.h @@ -169,6 +169,8 @@ public: __forceinline void setWString(const char *name, const wchar_t* value) { db_set_ws(NULL, m_szModuleName, name, value); } __forceinline void setWString(MCONTACT hContact, const char *name, const wchar_t* value) { db_set_ws(hContact, m_szModuleName, name, value); } + __forceinline contact_iter acc_contact_iter() const { return contact_iter(m_szModuleName); } + ////////////////////////////////////////////////////////////////////////////////////// // Service functions diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib index 4333d58e28..e931186ad7 100644 Binary files a/libs/win32/mir_app.lib and b/libs/win32/mir_app.lib differ diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib index bb0b07d244..817ec22458 100644 Binary files a/libs/win64/mir_app.lib and b/libs/win64/mir_app.lib differ 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); diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index 0b450a9fda..7014e6e51d 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -69,7 +69,7 @@ CDiscordProto::CDiscordProto(const char *proto_name, const wchar_t *username) : Clist_GroupCreate(0, m_wszDefaultGroup); // Fill users list - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { CDiscordUser *pNew = new CDiscordUser(getId(hContact, DB_KEY_ID)); pNew->hContact = hContact; pNew->channelId = getId(hContact, DB_KEY_CHANNELID); diff --git a/protocols/EmLanProto/src/mlan.cpp b/protocols/EmLanProto/src/mlan.cpp index 6cd8255697..aedb605b13 100644 --- a/protocols/EmLanProto/src/mlan.cpp +++ b/protocols/EmLanProto/src/mlan.cpp @@ -111,7 +111,7 @@ void CMLan::SetMirandaStatus(u_int status) void CMLan::SetAllOffline() { - for (MCONTACT hContact = db_find_first(PROTONAME); hContact; hContact = db_find_next(hContact, PROTONAME)) { + for (auto &hContact : contact_iter(PROTONAME)) { db_set_w(hContact, PROTONAME, "Status", ID_STATUS_OFFLINE); db_unset(hContact, PROTONAME, "IP"); } @@ -205,7 +205,7 @@ void CMLan::SendPacketExt(TPacket& pak, u_long addr) MCONTACT CMLan::FindContact(in_addr addr, const char* nick, bool add_to_list, bool make_permanent, bool make_visible, u_int status) { - for (MCONTACT res = db_find_first(PROTONAME); res; res = db_find_next(res, PROTONAME)) { + for (auto &res : contact_iter(PROTONAME)) { u_long caddr = db_get_dw(res, PROTONAME, "ipaddr", -1); if (caddr == addr.S_un.S_addr) { if (make_permanent) diff --git a/protocols/FacebookRM/src/chat.cpp b/protocols/FacebookRM/src/chat.cpp index 266818d1af..565f434872 100644 --- a/protocols/FacebookRM/src/chat.cpp +++ b/protocols/FacebookRM/src/chat.cpp @@ -500,7 +500,7 @@ void FacebookProto::LoadParticipantsNames(facebook_chatroom *fbc) void FacebookProto::JoinChatrooms() { - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (!isChatRoom(hContact)) continue; diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp index be4c056871..889b042fa3 100644 --- a/protocols/FacebookRM/src/contacts.cpp +++ b/protocols/FacebookRM/src/contacts.cpp @@ -90,7 +90,7 @@ MCONTACT FacebookProto::ChatIDToHContact(const std::string &chat_id) } // Go through all local contacts - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (!IsMyContact(hContact, true)) continue; @@ -122,7 +122,7 @@ MCONTACT FacebookProto::ContactIDToHContact(const std::string &user_id) } // Go through all local contacts - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (isChatRoom(hContact)) continue; @@ -150,7 +150,7 @@ std::string FacebookProto::ThreadIDToContactID(const std::string &thread_id) } // Go through all local contacts - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (!IsMyContact(hContact)) continue; diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 4455126c61..a30cdbbf6c 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -50,7 +50,7 @@ void FacebookProto::ProcessFriendList(void*) ParseFriends(&resp.data, &friends, loadAllContacts); // Check and update old contacts - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (isChatRoom(hContact)) continue; diff --git a/protocols/Gadu-Gadu/src/core.cpp b/protocols/Gadu-Gadu/src/core.cpp index 266ff97786..f34163ad81 100644 --- a/protocols/Gadu-Gadu/src/core.cpp +++ b/protocols/Gadu-Gadu/src/core.cpp @@ -1373,7 +1373,7 @@ void GaduProto::setalloffline() debugLogA("setalloffline(): started. Setting buddies offline"); setWord(GG_KEY_STATUS, ID_STATUS_OFFLINE); - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { setWord(hContact, GG_KEY_STATUS, ID_STATUS_OFFLINE); // Clear IP and port settings delSetting(hContact, GG_KEY_CLIENTIP); @@ -1437,7 +1437,7 @@ void GaduProto::notifyall() debugLogA("notifyall(): Subscribing notification to all users"); // Readup count int count = 0; - for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) + for (auto &hContact : acc_contact_iter()) count++; // Readup list @@ -1454,7 +1454,7 @@ void GaduProto::notifyall() char *types = (char*)calloc(sizeof(char), count); int cc = 0; - for (hContact = db_find_first(m_szModuleName); hContact && cc < count; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (uins[cc] = getDword(hContact, GG_KEY_UIN, 0)) { if ((getWord(hContact, GG_KEY_APPARENT, (WORD)ID_STATUS_ONLINE) == ID_STATUS_OFFLINE) || db_get_b(hContact, "CList", "NotOnList", 0)) @@ -1490,7 +1490,7 @@ MCONTACT GaduProto::getcontact(uin_t uin, int create, int inlist, wchar_t *szNic debugLogA("getcontact(): uin=%d create=%d inlist=%d", uin, create, inlist); #endif // Look for contact in DB - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if ((uin_t)getDword(hContact, GG_KEY_UIN, 0) == uin && !isChatRoom(hContact)) { if (inlist) { db_unset(hContact, "CList", "NotOnList"); diff --git a/protocols/Gadu-Gadu/src/groupchat.cpp b/protocols/Gadu-Gadu/src/groupchat.cpp index 2126cfdb53..7e6d7a823f 100644 --- a/protocols/Gadu-Gadu/src/groupchat.cpp +++ b/protocols/Gadu-Gadu/src/groupchat.cpp @@ -407,7 +407,7 @@ static void gg_gc_resetclistopts(HWND hwndList) static int gg_gc_countcheckmarks(HWND hwndList) { int count = 0; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0); if (hItem && SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) ++count; @@ -459,7 +459,7 @@ static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wPa // Create new participiants table uin_t* participants = (uin_t*)calloc(count, sizeof(uin_t)); gg->debugLogA("gg_gc_openconfdlg(): WM_COMMAND IDOK Opening new conference for %d contacts.", count); - for (MCONTACT hContact = db_find_first(); hContact && i < count; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0); if (hItem && SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) { MCONTACT hMetaContact = gg_getsubcontact(gg, hContact); // MetaContacts support @@ -508,7 +508,7 @@ static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wPa break; // Delete non-gg contacts - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { MCONTACT hItem = (MCONTACT)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem) { MCONTACT hMetaContact = gg_getsubcontact(gg, hContact); // MetaContacts support diff --git a/protocols/Gadu-Gadu/src/import.cpp b/protocols/Gadu-Gadu/src/import.cpp index 23c621ead5..ae8c96764f 100644 --- a/protocols/Gadu-Gadu/src/import.cpp +++ b/protocols/Gadu-Gadu/src/import.cpp @@ -25,7 +25,7 @@ char *gg_makecontacts(GaduProto *gg, int cr) string_t s = string_init(nullptr); // Readup contacts - for (MCONTACT hContact = db_find_first(gg->m_szModuleName); hContact; hContact = db_find_next(hContact, gg->m_szModuleName)) { + for (auto &hContact : gg->acc_contact_iter()) { if (gg->isChatRoom(hContact)) continue; diff --git a/protocols/ICQCorp/src/protocol.cpp b/protocols/ICQCorp/src/protocol.cpp index 57f683a63b..41cdc81cd3 100644 --- a/protocols/ICQCorp/src/protocol.cpp +++ b/protocols/ICQCorp/src/protocol.cpp @@ -1111,7 +1111,7 @@ void ICQ::updateContactList() //HANDLE hContact; ICQUser *u; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { proto = GetContactProto(hContact); if (proto && !mir_strcmp(proto, protoName)) { if ((u = getUserByContact(hContact)) == nullptr) { diff --git a/protocols/IRCG/src/clist.cpp b/protocols/IRCG/src/clist.cpp index 8409c501e7..b09b9b9248 100644 --- a/protocols/IRCG/src/clist.cpp +++ b/protocols/IRCG/src/clist.cpp @@ -140,7 +140,7 @@ bool CIrcProto::CList_SetAllOffline(BYTE ChatsToo) DisconnectAllDCCSessions(false); - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (isChatRoom(hContact)) continue; @@ -168,7 +168,7 @@ MCONTACT CIrcProto::CList_FindContact(CONTACT *user) wchar_t* lowercasename = mir_wstrdup(user->name); CharLower(lowercasename); - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (isChatRoom(hContact)) continue; diff --git a/protocols/IRCG/src/commandmonitor.cpp b/protocols/IRCG/src/commandmonitor.cpp index 05ca521f17..8ba7681450 100644 --- a/protocols/IRCG/src/commandmonitor.cpp +++ b/protocols/IRCG/src/commandmonitor.cpp @@ -141,7 +141,7 @@ VOID CALLBACK OnlineNotifTimerProc(HWND, UINT, UINT_PTR idEvent, DWORD) if (name.IsEmpty() && name2.IsEmpty()) { DBVARIANT dbv; - for (MCONTACT hContact = db_find_first(ppro->m_szModuleName); hContact; hContact = db_find_next(hContact, ppro->m_szModuleName)) { + for (auto &hContact : ppro->acc_contact_iter()) { if (ppro->isChatRoom(hContact)) continue; diff --git a/protocols/IcqOscarJ/src/icq_infoupdate.cpp b/protocols/IcqOscarJ/src/icq_infoupdate.cpp index 8ebdcbd7bf..b4f443aa2c 100644 --- a/protocols/IcqOscarJ/src/icq_infoupdate.cpp +++ b/protocols/IcqOscarJ/src/icq_infoupdate.cpp @@ -126,7 +126,7 @@ void CIcqProto::icq_RescanInfoUpdate() bInfoUpdateEnabled = 0; // freeze thread // Queue all outdated users - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) + for (auto &hContact : acc_contact_iter()) if (IsMetaInfoChanged(hContact)) // Queue user if (!icq_QueueUser(hContact)) { // The queue is full, pause queuing contacts bInfoPendingUsers = 1; diff --git a/protocols/IcqOscarJ/src/icq_proto.cpp b/protocols/IcqOscarJ/src/icq_proto.cpp index 25ba07ecd5..21b99bdd01 100644 --- a/protocols/IcqOscarJ/src/icq_proto.cpp +++ b/protocols/IcqOscarJ/src/icq_proto.cpp @@ -259,7 +259,7 @@ int CIcqProto::OnModulesLoaded(WPARAM, LPARAM) ModuleLoad(0, 0); InitXStatusItems(FALSE); - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { DWORD bXStatus = getContactXStatus(hContact); if (bXStatus > 0) setContactExtraIcon(hContact, bXStatus); diff --git a/protocols/IcqOscarJ/src/icq_server.cpp b/protocols/IcqOscarJ/src/icq_server.cpp index 00c7f46806..b71737b5c6 100644 --- a/protocols/IcqOscarJ/src/icq_server.cpp +++ b/protocols/IcqOscarJ/src/icq_server.cpp @@ -178,7 +178,7 @@ void __cdecl CIcqProto::ServerThread(serverthread_start_info *infoParam) StopAvatarThread(); // Offline all contacts - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (getContactStatus(hContact) == ID_STATUS_OFFLINE) continue; diff --git a/protocols/IcqOscarJ/src/icq_servlist.cpp b/protocols/IcqOscarJ/src/icq_servlist.cpp index 54602dd8f5..b61fee4701 100644 --- a/protocols/IcqOscarJ/src/icq_servlist.cpp +++ b/protocols/IcqOscarJ/src/icq_servlist.cpp @@ -858,9 +858,7 @@ void CIcqProto::LoadServerIDs() nGroups = nServerIDListCount - nStart; - MCONTACT hContact = db_find_first(m_szModuleName); - - while (hContact) { // search all our contacts, reserve their server IDs + for (auto &hContact : acc_contact_iter()) { if (wSrvID = getWord(hContact, DBSETTING_SERVLIST_ID, 0)) { ReserveServerID(wSrvID, SSIT_ITEM, 0); nContacts++; @@ -877,8 +875,6 @@ void CIcqProto::LoadServerIDs() ReserveServerID(wSrvID, SSIT_ITEM, 0); nIgnores++; } - - hContact = db_find_next(hContact, m_szModuleName); } l.unlock(); @@ -1201,9 +1197,7 @@ void* CIcqProto::collectBuddyGroup(WORD wGroupID, int *count) MCONTACT hContact; WORD wItemID; - hContact = db_find_first(m_szModuleName); - - while (hContact) { // search all contacts + for (auto &hContact : acc_contact_iter()) { if (wGroupID == getWord(hContact, DBSETTING_SERVLIST_GROUP, 0)) { // add only buddys from specified group wItemID = getWord(hContact, DBSETTING_SERVLIST_ID, 0); @@ -1214,8 +1208,6 @@ void* CIcqProto::collectBuddyGroup(WORD wGroupID, int *count) if (!count) break; } } - - hContact = db_find_next(hContact, m_szModuleName); } if (count) @@ -1231,8 +1223,7 @@ void* CIcqProto::collectGroups(int *count) int i; WORD wGroupID; - MCONTACT hContact = db_find_first(m_szModuleName); - while (hContact) { // search all contacts + for (auto &hContact : acc_contact_iter()) { if (wGroupID = getWord(hContact, DBSETTING_SERVLIST_GROUP, 0)) { // add only valid IDs for (i = 0; i < cnt; i++) // check for already added ids if (buf[i] == wGroupID) @@ -1244,8 +1235,6 @@ void* CIcqProto::collectGroups(int *count) buf[i] = wGroupID; } } - - hContact = db_find_next(hContact, m_szModuleName); } *count = cnt << 1; diff --git a/protocols/IcqOscarJ/src/icq_uploadui.cpp b/protocols/IcqOscarJ/src/icq_uploadui.cpp index b841f1eade..5991d7cfcc 100644 --- a/protocols/IcqOscarJ/src/icq_uploadui.cpp +++ b/protocols/IcqOscarJ/src/icq_uploadui.cpp @@ -52,8 +52,7 @@ static void UpdateAllContactsCheckmark(HWND hwndList, CIcqProto* ppro, HANDLE ph { int check = 1; - MCONTACT hContact = db_find_first(ppro->m_szModuleName); - while (hContact) { + for (auto &hContact : ppro->acc_contact_iter()) { HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0); if (hItem) { if (!SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) { // if any of our contacts is unchecked, uncheck all contacts as well @@ -61,7 +60,6 @@ static void UpdateAllContactsCheckmark(HWND hwndList, CIcqProto* ppro, HANDLE ph break; } } - hContact = db_find_next(hContact, ppro->m_szModuleName); } SendMessage(hwndList, CLM_SETCHECKMARK, (WPARAM)phItemAll, check); @@ -74,8 +72,7 @@ static int UpdateCheckmarks(HWND hwndList, CIcqProto* ppro, HANDLE phItemAll) int bAll = 1; bListInit = 1; // lock CLC events - MCONTACT hContact = db_find_first(ppro->m_szModuleName); - while (hContact) { + for (auto &hContact : ppro->acc_contact_iter()) { HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0); if (hItem) { if (ppro->getWord(hContact, DBSETTING_SERVLIST_ID, 0)) @@ -83,7 +80,6 @@ static int UpdateCheckmarks(HWND hwndList, CIcqProto* ppro, HANDLE phItemAll) else bAll = 0; } - hContact = db_find_next(hContact, ppro->m_szModuleName); } // Update the "All contacts" checkmark @@ -97,7 +93,7 @@ static int UpdateCheckmarks(HWND hwndList, CIcqProto* ppro, HANDLE phItemAll) static void DeleteOtherContactsFromControl(HWND hCtrl, CIcqProto* ppro) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendMessage(hCtrl, CLM_FINDCONTACT, hContact, 0); if (hItem) if (!ppro->IsICQContact(hContact)) @@ -835,12 +831,10 @@ static INT_PTR CALLBACK DlgProcUploadList(HWND hwndDlg, UINT message, WPARAM wPa if (nm->flags&CLNF_ISINFO) { int check = SendMessage(hClist, CLM_GETCHECKMARK, (WPARAM)hItemAll, 0); - hContact = db_find_first(ppro->m_szModuleName); - while (hContact) { + for (auto &hContact : ppro->acc_contact_iter()) { HANDLE hItem = (HANDLE)SendMessage(hClist, CLM_FINDCONTACT, hContact, 0); if (hItem) SendMessage(hClist, CLM_SETCHECKMARK, (WPARAM)hItem, check); - hContact = db_find_next(hContact, ppro->m_szModuleName); } } else UpdateAllContactsCheckmark(hClist, ppro, hItemAll); diff --git a/protocols/IcqOscarJ/src/utilities.cpp b/protocols/IcqOscarJ/src/utilities.cpp index e7af9c8a33..ceaa122129 100644 --- a/protocols/IcqOscarJ/src/utilities.cpp +++ b/protocols/IcqOscarJ/src/utilities.cpp @@ -355,15 +355,11 @@ void CIcqProto::InitContactsCache() // build cache mir_cslock l(contactsCacheMutex); - MCONTACT hContact = db_find_first(m_szModuleName); - - while (hContact) { + for (auto &hContact : acc_contact_iter()) { DWORD dwUin; uid_str szUid; if (!getContactUid(hContact, &dwUin, &szUid)) AddToContactsCache(hContact, dwUin, szUid); - - hContact = db_find_next(hContact, m_szModuleName); } } @@ -421,17 +417,12 @@ MCONTACT CIcqProto::HContactFromUIN(DWORD dwUin, int *Added) if (hContact) return hContact; - hContact = db_find_first(m_szModuleName); - while (hContact) { - DWORD dwContactUin; - - dwContactUin = getContactUin(hContact); + for (auto &hContact : acc_contact_iter()) { + DWORD dwContactUin = getContactUin(hContact); if (dwContactUin == dwUin) { AddToContactsCache(hContact, dwUin, nullptr); return hContact; } - - hContact = db_find_next(hContact, m_szModuleName); } // not present: add @@ -489,8 +480,7 @@ MCONTACT CIcqProto::HContactFromUID(DWORD dwUin, const char *szUid, int *Added) if (hContact) return hContact; - hContact = db_find_first(m_szModuleName); - while (hContact) { + for (auto &hContact : acc_contact_iter()) { DWORD dwContactUin; uid_str szContactUid; if (!getContactUid(hContact, &dwContactUin, &szContactUid)) { @@ -501,7 +491,6 @@ MCONTACT CIcqProto::HContactFromUID(DWORD dwUin, const char *szUid, int *Added) return hContact; } } - hContact = db_find_next(hContact, m_szModuleName); } //not present: add @@ -811,9 +800,7 @@ void CIcqProto::ResetSettingsOnListReload() setWord("SrvRecordCount", 0); delSetting(DBSETTING_SERVLIST_UNHANDLED); - MCONTACT hContact = db_find_first(m_szModuleName); - - while (hContact) { + for (auto &hContact : acc_contact_iter()) { // All these values will be restored during the serv-list receive setWord(hContact, DBSETTING_SERVLIST_ID, 0); setWord(hContact, DBSETTING_SERVLIST_GROUP, 0); @@ -822,8 +809,6 @@ void CIcqProto::ResetSettingsOnListReload() delSetting(hContact, DBSETTING_SERVLIST_IGNORE); setByte(hContact, "Auth", 0); delSetting(hContact, DBSETTING_SERVLIST_DATA); - - hContact = db_find_next(hContact, m_szModuleName); } FlushSrvGroupsCache(); @@ -835,9 +820,7 @@ void CIcqProto::ResetSettingsOnConnect() setByte("SrvVisibility", 0); setDword("IdleTS", 0); - MCONTACT hContact = db_find_first(m_szModuleName); - - while (hContact) { + for (auto &hContact : acc_contact_iter()) { setDword(hContact, "LogonTS", 0); setDword(hContact, "IdleTS", 0); setDword(hContact, "TickTS", 0); @@ -846,8 +829,6 @@ void CIcqProto::ResetSettingsOnConnect() // All these values will be restored during the login if (getContactStatus(hContact) != ID_STATUS_OFFLINE) setWord(hContact, "Status", ID_STATUS_OFFLINE); - - hContact = db_find_next(hContact, m_szModuleName); } } @@ -856,9 +837,7 @@ void CIcqProto::ResetSettingsOnLoad() setDword("IdleTS", 0); setDword("LogonTS", 0); - MCONTACT hContact = db_find_first(m_szModuleName); - - while (hContact) { + for (auto &hContact : acc_contact_iter()) { setDword(hContact, "LogonTS", 0); setDword(hContact, "IdleTS", 0); setDword(hContact, "TickTS", 0); @@ -870,8 +849,6 @@ void CIcqProto::ResetSettingsOnLoad() delSetting(hContact, DBSETTING_XSTATUS_MSG); } setByte(hContact, "DCStatus", 0); - - hContact = db_find_next(hContact, m_szModuleName); } } diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp index a2eeaf620f..c81f133583 100644 --- a/protocols/JabberG/src/jabber_chat.cpp +++ b/protocols/JabberG/src/jabber_chat.cpp @@ -654,7 +654,7 @@ class CGroupchatInviteDlg : public CJabberDlgBase void FilterList(CCtrlClc *) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { char *proto = GetContactProto(hContact); if (mir_strcmp(proto, m_proto->m_szModuleName) || m_proto->isChatRoom(hContact)) if (HANDLE hItem = m_clc.FindContact(hContact)) @@ -763,7 +763,7 @@ public: HWND hwndList = GetDlgItem(m_hwnd, IDC_CLIST); // invite users from roster - for (MCONTACT hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) { + for (auto &hContact : m_proto->acc_contact_iter()) { if (m_proto->isChatRoom(hContact)) continue; diff --git a/protocols/JabberG/src/jabber_icolib.cpp b/protocols/JabberG/src/jabber_icolib.cpp index 5eb0a99b24..503937a5d0 100644 --- a/protocols/JabberG/src/jabber_icolib.cpp +++ b/protocols/JabberG/src/jabber_icolib.cpp @@ -444,7 +444,7 @@ BOOL CJabberProto::DBCheckIsTransportedContact(const wchar_t *jid, MCONTACT hCon void CJabberProto::CheckAllContactsAreTransported() { - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { ptrW jid(getWStringA(hContact, "jid")); if (jid) DBCheckIsTransportedContact(jid, hContact); diff --git a/protocols/JabberG/src/jabber_list.cpp b/protocols/JabberG/src/jabber_list.cpp index 94ba7846e8..51beefb3dc 100644 --- a/protocols/JabberG/src/jabber_list.cpp +++ b/protocols/JabberG/src/jabber_list.cpp @@ -89,7 +89,7 @@ void JABBER_RESOURCE_STATUS::Release() void CJabberProto::ListInit(void) { - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (isChatRoom(hContact)) { ptrW jid(getWStringA(hContact, "ChatRoomID")); if (jid != nullptr) diff --git a/protocols/JabberG/src/jabber_opt.cpp b/protocols/JabberG/src/jabber_opt.cpp index 94ba4caf28..54ee815d48 100755 --- a/protocols/JabberG/src/jabber_opt.cpp +++ b/protocols/JabberG/src/jabber_opt.cpp @@ -1021,7 +1021,7 @@ void CJabberProto::_RosterHandleGetRequest(HXML node, CJabberIqInfo*) } // now it is require to process whole contact list to add not in roster contacts - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { ptrW tszJid(getWStringA(hContact, "jid")); if (tszJid == nullptr) continue; diff --git a/protocols/JabberG/src/jabber_privacy.cpp b/protocols/JabberG/src/jabber_privacy.cpp index 4e37896abd..32ee36c4dc 100644 --- a/protocols/JabberG/src/jabber_privacy.cpp +++ b/protocols/JabberG/src/jabber_privacy.cpp @@ -422,7 +422,7 @@ public: SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_RESETCONTENT, 0, 0); { - for (MCONTACT hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) { + for (auto &hContact : m_proto->acc_contact_iter()) { ptrW jid( m_proto->getWStringA(hContact, "jid")); if (jid != nullptr) SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_ADDSTRING, 0, jid); @@ -1304,7 +1304,7 @@ void CJabberDlgPrivacyLists::CListResetOptions(HWND) void CJabberDlgPrivacyLists::CListFilter(HWND) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { char *proto = GetContactProto(hContact); if (!proto || mir_strcmp(proto, m_proto->m_szModuleName)) if (HANDLE hItem = m_clcClist.FindContact(hContact)) @@ -1361,7 +1361,7 @@ void CJabberDlgPrivacyLists::CListApplyList(HWND hwndList, CPrivacyList *pList) CListResetIcons(hwndList, hItem, bHideIcons); } - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = m_clcClist.FindContact(hContact); if (hItem) CListResetIcons(hwndList, hItem, bHideIcons); @@ -1459,7 +1459,7 @@ void CJabberDlgPrivacyLists::CListBuildList(HWND hwndList, CPrivacyList *pList) pList->AddRule(Jid, szJid, FALSE, dwOrder++, dwPackets); } - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { hItem = m_clcClist.FindContact(hContact); ptrW jid( m_proto->getWStringA(hContact, "jid")); diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index eedaec74af..e75eb2fdfa 100755 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -301,7 +301,7 @@ int CJabberProto::OnModulesLoadedEx(WPARAM, LPARAM) CheckAllContactsAreTransported(); // Set all contacts to offline - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { SetContactOfflineStatus(hContact); if (getByte(hContact, "IsTransport", 0)) { diff --git a/protocols/JabberG/src/jabber_rc.cpp b/protocols/JabberG/src/jabber_rc.cpp index e0201f51ff..5343ea2312 100644 --- a/protocols/JabberG/src/jabber_rc.cpp +++ b/protocols/JabberG/src/jabber_rc.cpp @@ -464,7 +464,7 @@ int CJabberProto::AdhocOptionsHandler(HXML, CJabberIqInfo *pInfo, CJabberAdhocSe int CJabberProto::RcGetUnreadEventsCount() { int nEventsSent = 0; - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { ptrW jid( getWStringA(hContact, "jid")); if (jid == nullptr) continue; @@ -550,7 +550,7 @@ int CJabberProto::AdhocForwardHandler(HXML, CJabberIqInfo *pInfo, CJabberAdhocSe m_bRcMarkMessagesAsRead = bRemoveCListEvents ? 1 : 0; int nEventsSent = 0; - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { ptrW tszJid( getWStringA(hContact, "jid")); if (tszJid == nullptr) continue; diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index a8b2b49bd4..dbadaa861f 100755 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -521,7 +521,7 @@ recvRest: // Set all contacts to offline debugLogA("1"); - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) + for (auto &hContact : acc_contact_iter()) SetContactOfflineStatus(hContact); debugLogA("2"); diff --git a/protocols/MRA/src/MraProto.cpp b/protocols/MRA/src/MraProto.cpp index 03cd7f2336..2dd3b590a7 100644 --- a/protocols/MRA/src/MraProto.cpp +++ b/protocols/MRA/src/MraProto.cpp @@ -90,7 +90,7 @@ int CMraProto::OnModulesLoaded(WPARAM, LPARAM) HookProtoEvent(ME_CLIST_GROUPCHANGE, &CMraProto::OnGroupChanged); // всех в offline // тк unsaved values сохран¤ютс¤ их нужно инициализировать - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact != NULL; hContact = db_find_next(hContact, m_szModuleName)) + for (auto &hContact : acc_contact_iter()) SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID | SCBIF_GROUP_ID | SCBIF_SERVER_FLAG | SCBIF_STATUS), -1, -1, 0, 0, ID_STATUS_OFFLINE, nullptr, nullptr, nullptr); // unsaved values @@ -462,7 +462,7 @@ int CMraProto::SetStatus(int iNewStatus) // всех в offline, только если мы бывали подключены if (dwOldStatusMode > ID_STATUS_OFFLINE) - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) + for (auto &hContact : acc_contact_iter()) SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID | SCBIF_GROUP_ID | SCBIF_SERVER_FLAG | SCBIF_STATUS), -1, -1, 0, 0, ID_STATUS_OFFLINE, nullptr, nullptr, nullptr); if (m_hConnection != nullptr) diff --git a/protocols/MRA/src/Mra_functions.cpp b/protocols/MRA/src/Mra_functions.cpp index da0902c387..7355eb65b8 100644 --- a/protocols/MRA/src/Mra_functions.cpp +++ b/protocols/MRA/src/Mra_functions.cpp @@ -510,7 +510,7 @@ MCONTACT CMraProto::MraHContactFromEmail(const CMStringA &szEmail, BOOL bAddIfNe //check not already on list CMStringA szEMailLocal; - for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (mraGetStringA(hContact, "e-mail", szEMailLocal)) if (szEMailLocal == szEmail) { if (bTemporary == FALSE) diff --git a/protocols/MRA/src/Mra_menus.cpp b/protocols/MRA/src/Mra_menus.cpp index 6d26c956bb..431e42dcea 100644 --- a/protocols/MRA/src/Mra_menus.cpp +++ b/protocols/MRA/src/Mra_menus.cpp @@ -31,7 +31,7 @@ INT_PTR CMraProto::MraUpdateAllUsersInfo(WPARAM, LPARAM) return 0; if (MessageBox(nullptr, TranslateT("Are you sure?"), TranslateT(MRA_UPD_ALL_USERS_INFO_STR), MB_YESNO | MB_ICONQUESTION) == IDYES) { - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { CMStringA szEmail; if (mraGetStringA(hContact, "e-mail", szEmail)) MraWPRequestByEMail(hContact, ACKTYPE_GETINFO, szEmail); @@ -43,7 +43,7 @@ INT_PTR CMraProto::MraUpdateAllUsersInfo(WPARAM, LPARAM) INT_PTR CMraProto::MraCheckUpdatesUsersAvt(WPARAM, LPARAM) { if (MessageBox(nullptr, TranslateT("Are you sure?"), TranslateT(MRA_CHK_USERS_AVATARS_STR), MB_YESNO | MB_ICONQUESTION) == IDYES) { - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { CMStringA szEmail; if (mraGetStringA(hContact, "e-mail", szEmail)) if (!IsEMailChatAgent(szEmail)) @@ -59,7 +59,7 @@ INT_PTR CMraProto::MraRequestAuthForAll(WPARAM, LPARAM) return 0; if (MessageBox(nullptr, TranslateT("Are you sure?"), TranslateT(MRA_REQ_AUTH_FOR_ALL_STR), MB_YESNO | MB_ICONQUESTION) == IDYES) { - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { DWORD dwContactSeverFlags; if (GetContactBasicInfoW(hContact, nullptr, nullptr, nullptr, &dwContactSeverFlags, nullptr, nullptr, nullptr, nullptr) == NO_ERROR) if (dwContactSeverFlags & CONTACT_INTFLAG_NOT_AUTHORIZED && dwContactSeverFlags != -1) diff --git a/protocols/MRA/src/Mra_proto.cpp b/protocols/MRA/src/Mra_proto.cpp index 0cf552080d..ea5663733d 100644 --- a/protocols/MRA/src/Mra_proto.cpp +++ b/protocols/MRA/src/Mra_proto.cpp @@ -1308,7 +1308,7 @@ bool CMraProto::CmdClist2(BinBuffer &buf) if (mraGetStringW(NULL, "AuthMessage", wszAuthMessage) == FALSE) // def auth message wszAuthMessage = TranslateW(MRA_DEFAULT_AUTH_MESSAGE); - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (GetContactBasicInfoW(hContact, &dwID, nullptr, nullptr, nullptr, nullptr, &email, nullptr, nullptr) == NO_ERROR) if (dwID == -1) { if (IsEMailChatAgent(email)) {// чат: ещё раз запросим авторизацию, пометим как видимый в списке, постоянный @@ -1337,7 +1337,7 @@ bool CMraProto::CmdClist2(BinBuffer &buf) } else { // контакт лист почемуто не получили // всех в offline и id в нестандарт - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID | SCBIF_GROUP_ID | SCBIF_SERVER_FLAG | SCBIF_STATUS), -1, -2, 0, 0, ID_STATUS_OFFLINE, nullptr, nullptr, nullptr); // request user info from server diff --git a/protocols/MSN/src/msn_chat.cpp b/protocols/MSN/src/msn_chat.cpp index 804cb64951..c484d9f2f6 100644 --- a/protocols/MSN/src/msn_chat.cpp +++ b/protocols/MSN/src/msn_chat.cpp @@ -241,10 +241,9 @@ void CMsnProto::MSN_GCProcessThreadActivity(ezxml_t xmli, const wchar_t *mChatID void CMsnProto::MSN_GCRefreshThreadsInfo(void) { CMStringA buf; - MCONTACT hContact; int nThreads = 0; - for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (isChatRoom(hContact) != 0) { DBVARIANT dbv; if (getString(hContact, "ChatRoomID", &dbv) == 0) { diff --git a/protocols/MSN/src/msn_contact.cpp b/protocols/MSN/src/msn_contact.cpp index bf9de7dbfd..ae5abebf9d 100644 --- a/protocols/MSN/src/msn_contact.cpp +++ b/protocols/MSN/src/msn_contact.cpp @@ -53,11 +53,7 @@ MCONTACT CMsnProto::MSN_HContactFromEmail(const char* wlid, const char* msnNick, MCONTACT CMsnProto::MSN_HContactFromChatID(const char* wlid) { - MCONTACT hContact = NULL; - - for (hContact = db_find_first(m_szModuleName); hContact; - hContact = db_find_next(hContact, m_szModuleName)) - { + for (auto &hContact : acc_contact_iter()) { if (isChatRoom(hContact) != 0) { DBVARIANT dbv; if (getString(hContact, "ChatRoomID", &dbv) == 0) { diff --git a/protocols/MSN/src/msn_misc.cpp b/protocols/MSN/src/msn_misc.cpp index 78ec94f5dd..8b82cd9231 100644 --- a/protocols/MSN/src/msn_misc.cpp +++ b/protocols/MSN/src/msn_misc.cpp @@ -674,11 +674,8 @@ void CMsnProto::MSN_FetchRecentMessages(time_t since) /* Assuming that you want all messages that were sent after the last * user conversation according to DB */ - MCONTACT hContact; MEVENT hDbEvent; - for (hContact = db_find_first(m_szModuleName); hContact; - hContact = db_find_next(hContact, m_szModuleName)) - { + for (auto &hContact : acc_contact_iter()) { if (!(hDbEvent = db_event_last(hContact))) continue; diff --git a/protocols/MSN/src/msn_proto.cpp b/protocols/MSN/src/msn_proto.cpp index d4498913e1..85c2344b32 100644 --- a/protocols/MSN/src/msn_proto.cpp +++ b/protocols/MSN/src/msn_proto.cpp @@ -88,7 +88,7 @@ CMsnProto::CMsnProto(const char* aProtoName, const wchar_t* aUserName) : LoadOptions(); - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { delSetting(hContact, "Status"); delSetting(hContact, "IdleTS"); delSetting(hContact, "p2pMsgId"); diff --git a/protocols/MinecraftDynmap/src/chat.cpp b/protocols/MinecraftDynmap/src/chat.cpp index 5b5a52cd81..d51d02fcd1 100644 --- a/protocols/MinecraftDynmap/src/chat.cpp +++ b/protocols/MinecraftDynmap/src/chat.cpp @@ -189,7 +189,7 @@ MCONTACT MinecraftDynmapProto::GetChatHandle() /*if (chatHandle_ != NULL) return chatHandle_; - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (db_get_b(hContact, m_szModuleName, "ChatRoom", 0) > 0) { ptrA id = db_get_sa(hContact, m_szModuleName, "ChatRoomId"); if (id != NULL && !strcmp(id, m_szModuleName)) diff --git a/protocols/Omegle/src/chat.cpp b/protocols/Omegle/src/chat.cpp index 1ff3b69bba..e3ab206286 100644 --- a/protocols/Omegle/src/chat.cpp +++ b/protocols/Omegle/src/chat.cpp @@ -336,7 +336,7 @@ MCONTACT OmegleProto::GetChatHandle() /*if (facy.chatHandle_ != NULL) return facy.chatHandle_; - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (db_get_b(hContact, m_szModuleName, "ChatRoom", 0) > 0) { ptrA id = db_get_sa(hContact, m_szModuleName, "ChatRoomId"); if (id != NULL && !mir_strcmp(id, m_szModuleName)) diff --git a/protocols/Sametime/src/sametime.cpp b/protocols/Sametime/src/sametime.cpp index dfb4166223..01770d382c 100644 --- a/protocols/Sametime/src/sametime.cpp +++ b/protocols/Sametime/src/sametime.cpp @@ -223,7 +223,7 @@ void CSametimeProto::SetAllOffline() { debugLogW(L"SetAllOffline() start"); - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (db_get_b(hContact, m_szModuleName, "ChatRoom", 0)) { db_delete_contact(hContact); continue; diff --git a/protocols/Sametime/src/session_announce_win.cpp b/protocols/Sametime/src/session_announce_win.cpp index 45c4dffa2d..50f564f1d3 100644 --- a/protocols/Sametime/src/session_announce_win.cpp +++ b/protocols/Sametime/src/session_announce_win.cpp @@ -40,7 +40,7 @@ INT_PTR CALLBACK SessionAnnounceDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wPara lvI.iItem = 0; lvI.iSubItem = 0; - for (MCONTACT hContact = db_find_first(proto->m_szModuleName); hContact; hContact = db_find_next(hContact, proto->m_szModuleName)) { + for (auto &hContact : proto->acc_contact_iter()) { if (db_get_b(hContact, proto->m_szModuleName, "ChatRoom", 0) == 0 && db_get_w(hContact, proto->m_szModuleName, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) { lvI.lParam = (LPARAM)hContact; diff --git a/protocols/Sametime/src/userlist.cpp b/protocols/Sametime/src/userlist.cpp index a61398189a..777d174aa0 100644 --- a/protocols/Sametime/src/userlist.cpp +++ b/protocols/Sametime/src/userlist.cpp @@ -4,7 +4,7 @@ MCONTACT CSametimeProto::FindContactByUserId(const char* id) { DBVARIANT dbv; - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (!db_get_utf(hContact, m_szModuleName, "stid", &dbv)) { if (dbv.pszVal && mir_strcmp(id, dbv.pszVal) == 0) { db_free(&dbv); @@ -204,7 +204,7 @@ void CSametimeProto::ExportContactsToList(mwSametimeList* user_list) mwIdBlock uid; GList* gl = nullptr; - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (!db_get_utf(hContact, m_szModuleName, "stid", &dbv)) { if (dbv.pszVal) { if (GetAwareIdFromContact(hContact, &id_block)) { @@ -223,7 +223,6 @@ void CSametimeProto::ExportContactsToList(mwSametimeList* user_list) db_free(&dbv); free(id_block.user); free(group_alias); - hContact = db_find_next(hContact, m_szModuleName); continue; } @@ -595,7 +594,7 @@ void CSametimeProto::UserListCreate() mwAwareIdBlock id_block; GList *gl = nullptr; - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (db_get_b(hContact, m_szModuleName, "ChatRoom", 0) == 0 /*&& proto && !mir_strcmp( PROTO, proto)*/) { if (!db_get_utf(hContact, m_szModuleName, "stid", &dbv)) { if (dbv.pszVal) { diff --git a/protocols/SkypeWeb/src/skype_contacts.cpp b/protocols/SkypeWeb/src/skype_contacts.cpp index bc10cf333f..956624daa9 100644 --- a/protocols/SkypeWeb/src/skype_contacts.cpp +++ b/protocols/SkypeWeb/src/skype_contacts.cpp @@ -59,12 +59,11 @@ MCONTACT CSkypeProto::GetContactFromAuthEvent(MEVENT hEvent) MCONTACT CSkypeProto::FindContact(const char *skypename) { - MCONTACT hContact = NULL; - for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) if (!mir_strcmpi(skypename, Contacts[hContact])) - break; - } - return hContact; + return hContact; + + return 0; } MCONTACT CSkypeProto::AddContact(const char *skypename, bool isTemporary) diff --git a/protocols/SkypeWeb/src/skype_dialogs.cpp b/protocols/SkypeWeb/src/skype_dialogs.cpp index 2af7213b51..6a58c70d38 100644 --- a/protocols/SkypeWeb/src/skype_dialogs.cpp +++ b/protocols/SkypeWeb/src/skype_dialogs.cpp @@ -39,7 +39,7 @@ CSkypeInviteDlg::CSkypeInviteDlg(CSkypeProto *proto) : void CSkypeInviteDlg::OnInitDialog() { - for (MCONTACT hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) { + for (auto &hContact : m_proto->acc_contact_iter()) { if (!m_proto->isChatRoom(hContact)) { wchar_t *ptszNick = pcli->pfnGetContactDisplayName(hContact, 0); m_combo.AddString(ptszNick, hContact); @@ -77,7 +77,7 @@ void CSkypeGCCreateDlg::OnInitDialog() void CSkypeGCCreateDlg::btnOk_OnOk(CCtrlButton*) { - for (MCONTACT hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) { + for (auto &hContact : m_proto->acc_contact_iter()) { if (!m_proto->isChatRoom(hContact)) { if (HANDLE hItem = m_clc.FindContact(hContact)) { if (m_clc.GetCheck(hItem)) { @@ -94,7 +94,7 @@ void CSkypeGCCreateDlg::btnOk_OnOk(CCtrlButton*) void CSkypeGCCreateDlg::FilterList(CCtrlClc *) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { char *proto = GetContactProto(hContact); if (mir_strcmp(proto, m_proto->m_szModuleName) || m_proto->isChatRoom(hContact)) if (HANDLE hItem = m_clc.FindContact(hContact)) diff --git a/protocols/SkypeWeb/src/skype_login.cpp b/protocols/SkypeWeb/src/skype_login.cpp index 2f4a4c6d14..cc145420b4 100644 --- a/protocols/SkypeWeb/src/skype_login.cpp +++ b/protocols/SkypeWeb/src/skype_login.cpp @@ -232,7 +232,7 @@ void CSkypeProto::OnCapabilitiesSended(const NETLIBHTTPREQUEST *response) SendRequest(new SetStatusRequest(MirandaToSkypeStatus(m_iDesiredStatus), li), &CSkypeProto::OnStatusChanged); LIST skypenames(1); - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) + for (auto &hContact : acc_contact_iter()) if (!isChatRoom(hContact)) skypenames.insert(getStringA(hContact, SKYPE_SETTINGS_ID)); diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp index e3d3c8c9c7..9bdfdc8bf3 100644 --- a/protocols/Steam/src/steam_contacts.cpp +++ b/protocols/Steam/src/steam_contacts.cpp @@ -2,7 +2,7 @@ void CSteamProto::SetAllContactStatuses(int status) { - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) + for (auto &hContact : acc_contact_iter()) SetContactStatus(hContact, status); } @@ -71,7 +71,7 @@ MCONTACT CSteamProto::GetContactFromAuthEvent(MEVENT hEvent) MCONTACT CSteamProto::GetContact(const char *steamId) { - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { ptrA cSteamId(getStringA(hContact, "SteamID")); if (!mir_strcmp(cSteamId, steamId)) return hContact; @@ -428,7 +428,7 @@ void CSteamProto::OnGotFriendList(const JSONNode &root, void*) } // Check and update contacts in database - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { ptrA steamId(getStringA(hContact, "SteamID")); if (steamId == nullptr) continue; diff --git a/protocols/Tox/src/tox_avatars.cpp b/protocols/Tox/src/tox_avatars.cpp index ad2ac177e8..2e39986fa8 100644 --- a/protocols/Tox/src/tox_avatars.cpp +++ b/protocols/Tox/src/tox_avatars.cpp @@ -64,7 +64,7 @@ void CToxProto::SetToxAvatar(const wchar_t* path) db_set_blob(NULL, m_szModuleName, TOX_SETTINGS_AVATAR_HASH, (void*)hash, TOX_HASH_LENGTH); if (IsOnline()) { - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (GetContactStatus(hContact) == ID_STATUS_OFFLINE) continue; @@ -162,7 +162,7 @@ INT_PTR CToxProto::SetMyAvatar(WPARAM, LPARAM lParam) } if (IsOnline()) { - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (GetContactStatus(hContact) == ID_STATUS_OFFLINE) continue; diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp index 5533d78983..7f945bf1a4 100644 --- a/protocols/Tox/src/tox_contacts.cpp +++ b/protocols/Tox/src/tox_contacts.cpp @@ -49,7 +49,7 @@ MCONTACT CToxProto::GetContact(const Tox *tox, const int friendNumber) MCONTACT CToxProto::GetContact(const char *pubKey) { MCONTACT hContact = NULL; - for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { ptrA contactPubKey(getStringA(hContact, TOX_SETTINGS_ID)); // check only public key part of address if (mir_strncmpi(pubKey, contactPubKey, TOX_PUBLIC_KEY_SIZE) == 0) diff --git a/protocols/Twitter/src/chat.cpp b/protocols/Twitter/src/chat.cpp index 3e0ed8e613..2be12c4f20 100644 --- a/protocols/Twitter/src/chat.cpp +++ b/protocols/Twitter/src/chat.cpp @@ -145,7 +145,7 @@ void TwitterProto::SetChatStatus(int status) { if (status == ID_STATUS_ONLINE) { // Add all friends to contact list - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (isChatRoom(hContact)) continue; diff --git a/protocols/Twitter/src/contacts.cpp b/protocols/Twitter/src/contacts.cpp index ff13bdff26..9e5d80c657 100644 --- a/protocols/Twitter/src/contacts.cpp +++ b/protocols/Twitter/src/contacts.cpp @@ -211,7 +211,7 @@ bool TwitterProto::IsMyContact(MCONTACT hContact, bool include_chat) MCONTACT TwitterProto::UsernameToHContact(const char *name) { - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (getByte(hContact, "ChatRoom")) continue; diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 07bf5cd0b5..918d9441da 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -158,7 +158,7 @@ wchar_t* CVkProto::GetUserStoredPassword() void CVkProto::SetAllContactStatuses(int iStatus) { debugLogA("CVkProto::SetAllContactStatuses (%d)", iStatus); - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (isChatRoom(hContact)) SetChatStatus(hContact, iStatus); else if (getWord(hContact, "Status") != iStatus) @@ -178,7 +178,7 @@ MCONTACT CVkProto::FindUser(LONG dwUserid, bool bCreate) if (!dwUserid) return 0; - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { LONG dbUserid = getDword(hContact, "ID", VK_INVALID_USER); if (dbUserid == VK_INVALID_USER) continue; @@ -204,7 +204,7 @@ MCONTACT CVkProto::FindChat(LONG dwUserid) if (!dwUserid) return 0; - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { LONG dbUserid = getDword(hContact, "vk_chat_id", VK_INVALID_USER); if (dbUserid == VK_INVALID_USER) continue; diff --git a/protocols/VKontakte/src/vk_dialogs.cpp b/protocols/VKontakte/src/vk_dialogs.cpp index 6e957b7b79..09eb855ccf 100644 --- a/protocols/VKontakte/src/vk_dialogs.cpp +++ b/protocols/VKontakte/src/vk_dialogs.cpp @@ -157,7 +157,7 @@ CVkInviteChatForm::CVkInviteChatForm(CVkProto *proto) : void CVkInviteChatForm::OnInitDialog() { - for (MCONTACT hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) { + for (auto &hContact : m_proto->acc_contact_iter()) { if (!m_proto->isChatRoom(hContact)) { wchar_t *pwszNick = pcli->pfnGetContactDisplayName(hContact, 0); m_cbxCombo.AddString(pwszNick, hContact); @@ -195,7 +195,7 @@ void CVkGCCreateForm::OnInitDialog() void CVkGCCreateForm::btnOk_OnOk(CCtrlButton*) { CMStringA szUIds; - for (MCONTACT hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) { + for (auto &hContact : m_proto->acc_contact_iter()) { if (m_proto->isChatRoom(hContact)) continue; @@ -219,7 +219,7 @@ void CVkGCCreateForm::btnOk_OnOk(CCtrlButton*) void CVkGCCreateForm::FilterList(CCtrlClc*) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { char *proto = GetContactProto(hContact); if (mir_strcmp(proto, m_proto->m_szModuleName) || m_proto->isChatRoom(hContact) || m_proto->getDword(hContact, "ID") == VK_FEED_USER) if (HANDLE hItem = m_clCList.FindContact(hContact)) diff --git a/protocols/VKontakte/src/vk_history.cpp b/protocols/VKontakte/src/vk_history.cpp index 09447ea84f..4781cb4cdb 100644 --- a/protocols/VKontakte/src/vk_history.cpp +++ b/protocols/VKontakte/src/vk_history.cpp @@ -61,7 +61,7 @@ INT_PTR __cdecl CVkProto::SvcGetAllServerHistory(WPARAM, LPARAM) if (IDNO == MessageBoxW(nullptr, str, TranslateT("Attention!"), MB_ICONWARNING | MB_YESNO)) return 0; - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { LONG userID = getDword(hContact, "ID", VK_INVALID_USER); if (userID == VK_INVALID_USER || userID == VK_FEED_USER) continue; diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index c7efb61344..044b6e5757 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -550,7 +550,7 @@ void CVkProto::RetrieveUsersInfo(bool bFreeOffline, bool bRepeat) CMStringA userIDs; int i = 0; - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { LONG userID = getDword(hContact, "ID", VK_INVALID_USER); if (userID == VK_INVALID_USER || userID == VK_FEED_USER || userID < 0) continue; @@ -602,7 +602,7 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe MCONTACT hContact; LIST arContacts(10, PtrKeySortT); - for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) + for (auto &hContact : acc_contact_iter()) if (!isChatRoom(hContact) && !IsGroupUser(hContact)) arContacts.insert((HANDLE)hContact); @@ -755,7 +755,7 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq LIST arContacts(10, PtrKeySortT); - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (!isChatRoom(hContact) && !IsGroupUser(hContact)) setByte(hContact, "Auth", 1); db_unset(hContact, m_szModuleName, "ReqAuth"); diff --git a/src/core/stdfile/src/file.cpp b/src/core/stdfile/src/file.cpp index ab5b5fa68f..4f9b2dcc13 100644 --- a/src/core/stdfile/src/file.cpp +++ b/src/core/stdfile/src/file.cpp @@ -271,7 +271,7 @@ void UpdateProtoFileTransferStatus(PROTOFILETRANSFERSTATUS *dest, PROTOFILETRANS static void RemoveUnreadFileEvents(void) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { MEVENT hDbEvent = db_event_firstUnread(hContact); while (hDbEvent) { DBEVENTINFO dbei = {}; diff --git a/src/core/stdmsg/src/msgoptions.cpp b/src/core/stdmsg/src/msgoptions.cpp index 34bb77028c..dbd9095c82 100644 --- a/src/core/stdmsg/src/msgoptions.cpp +++ b/src/core/stdmsg/src/msgoptions.cpp @@ -461,7 +461,7 @@ public: if (hItemUnknown && g_dat.bTypingUnknown) clist.SetCheck(hItemUnknown, 1); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = clist.FindContact(hContact); if (hItem && db_get_b(hContact, SRMMMOD, SRMSGSET_TYPING, defType)) clist.SetCheck(hItem, 1); @@ -476,7 +476,7 @@ public: if (hItemUnknown) g_dat.bTypingUnknown = clist.GetCheck(hItemUnknown); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = clist.FindContact(hContact); if (hItem) db_set_b(hContact, SRMMMOD, SRMSGSET_TYPING, clist.GetCheck(hItem)); diff --git a/src/core/stdmsg/src/msgs.cpp b/src/core/stdmsg/src/msgs.cpp index 0b99c01edc..30a4565263 100644 --- a/src/core/stdmsg/src/msgs.cpp +++ b/src/core/stdmsg/src/msgs.cpp @@ -240,7 +240,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)) { bool autoPopup = false; diff --git a/src/mir_app/src/DefaultExtraIcons.cpp b/src/mir_app/src/DefaultExtraIcons.cpp index 26e9ae9d1f..ec4e4315c2 100644 --- a/src/mir_app/src/DefaultExtraIcons.cpp +++ b/src/mir_app/src/DefaultExtraIcons.cpp @@ -312,7 +312,7 @@ void DefaultExtraIcons_Load() p.hExtraIcon = ExtraIcon_RegisterIcolib(p.name, p.desc, Skin_GetIconName(p.iSkinIcon), nullptr, 0, p.flags); } - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { SetExtraIcons(hContact); SetVisibility(hContact, -1, false); SetGender(hContact, -1, false); diff --git a/src/mir_app/src/ExtraIcon.cpp b/src/mir_app/src/ExtraIcon.cpp index a22b28b6ac..95d093feaf 100644 --- a/src/mir_app/src/ExtraIcon.cpp +++ b/src/mir_app/src/ExtraIcon.cpp @@ -67,7 +67,7 @@ void ExtraIcon::applyIcons() if (!isEnabled()) return; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { // Clear to assert that it will be cleared Clist_SetExtraIcon(hContact, m_slot, INVALID_HANDLE_VALUE); applyIcon(hContact); diff --git a/src/mir_app/src/chat_clist.cpp b/src/mir_app/src/chat_clist.cpp index e1d20e01bf..5fb50bca59 100644 --- a/src/mir_app/src/chat_clist.cpp +++ b/src/mir_app/src/chat_clist.cpp @@ -83,12 +83,10 @@ BOOL SetOffline(MCONTACT hContact, BOOL) BOOL SetAllOffline(BOOL, const char *pszModule) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter(pszModule)) { char *szProto = GetContactProto(hContact); if (!chatApi.MM_FindModule(szProto)) continue; - if (pszModule && mir_strcmp(pszModule, szProto)) - continue; int i = db_get_b(hContact, szProto, "ChatRoom", 0); if (i != 0) { db_set_w(hContact, szProto, "ApparentMode", 0); @@ -225,7 +223,7 @@ BOOL AddEvent(MCONTACT hContact, HICON hIcon, MEVENT hEvent, int type, wchar_t* MCONTACT FindRoom(const char *pszModule, const wchar_t *pszRoom) { - for (MCONTACT hContact = db_find_first(pszModule); hContact; hContact = db_find_next(hContact, pszModule)) { + for (auto &hContact : contact_iter(pszModule)) { if (!db_get_b(hContact, pszModule, "ChatRoom", 0)) continue; diff --git a/src/mir_app/src/clc.cpp b/src/mir_app/src/clc.cpp index a7c8b06698..8ece944316 100644 --- a/src/mir_app/src/clc.cpp +++ b/src/mir_app/src/clc.cpp @@ -248,7 +248,7 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam DWORD hitFlags; int hit; - ClcData *dat = (ClcData *) GetWindowLongPtr(hwnd, 0); + ClcData *dat = (ClcData *)GetWindowLongPtr(hwnd, 0); if (uMsg >= CLM_FIRST && uMsg < CLM_LAST) return cli.pfnProcessExternalMessages(hwnd, dat, uMsg, wParam, lParam); @@ -406,7 +406,7 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam int eq; if (dbcws->value.type == DBVT_ASCIIZ) - eq = !mir_wstrcmp(szFullName, _A2T(dbcws->value.pszVal+1)); + eq = !mir_wstrcmp(szFullName, _A2T(dbcws->value.pszVal + 1)); else eq = !mir_wstrcmp(szFullName, ptrW(mir_utf8decodeW(dbcws->value.pszVal + 1))); @@ -722,7 +722,7 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam if (!dat->bFilterSearch) dat->szQuickSearch[0] = 0; hit = cli.pfnGetRowByIndex(dat, dat->selection, &contact, &group); - if (hit == -1) + if (hit == -1) return 0; if (changeGroupExpand == 1 && contact->type == CLCIT_CONTACT) { @@ -1043,7 +1043,7 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam case DROPTARGET_OUTSIDE: if (pt.x >= 0 && pt.x < clRect.right && ((pt.y < 0 && pt.y > -dat->dragAutoScrollHeight) - || (pt.y >= clRect.bottom && pt.y < clRect.bottom + dat->dragAutoScrollHeight))) { + || (pt.y >= clRect.bottom && pt.y < clRect.bottom + dat->dragAutoScrollHeight))) { if (!dat->dragAutoScrolling) { if (pt.y < 0) dat->dragAutoScrolling = -1; @@ -1172,7 +1172,7 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam cli.pfnInvalidateRect(hwnd, nullptr, FALSE); if (dat->selection != -1) cli.pfnEnsureVisible(hwnd, dat, dat->selection, 0); - + if (hitFlags & (CLCHT_ONITEMICON | CLCHT_ONITEMLABEL)) { UpdateWindow(hwnd); cli.pfnDoSelectionDefaultAction(hwnd, dat); @@ -1236,7 +1236,7 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam hit = cli.pfnGetRowByIndex(dat, dat->selection, &contact, nullptr); if (hit == -1) break; - + if (contact->type == CLCIT_CONTACT) if (Clist_MenuProcessCommand(LOWORD(wParam), MPCF_CONTACTMENU, contact->hContact)) break; diff --git a/src/mir_app/src/clcitems.cpp b/src/mir_app/src/clcitems.cpp index 268135e832..704ecf0ef0 100644 --- a/src/mir_app/src/clcitems.cpp +++ b/src/mir_app/src/clcitems.cpp @@ -105,7 +105,7 @@ ClcGroup* fnAddGroup(HWND hwnd, ClcData *dat, const wchar_t *szName, DWORD flags group->totalMembers = 0; if (flags != (DWORD)-1 && pNextField == nullptr && calcTotalMembers) { DWORD style = GetWindowLongPtr(hwnd, GWL_STYLE); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { ClcCacheEntry *cache = cli.pfnGetCacheEntry(hContact); if (!mir_wstrcmp(cache->tszGroup, szName) && (style & CLS_SHOWHIDDEN || !cache->bIsHidden)) group->totalMembers++; @@ -359,7 +359,7 @@ void fnRebuildEntireList(HWND hwnd, ClcData *dat) cli.pfnAddGroup(hwnd, dat, szGroupName, groupFlags, i, 0); } - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { int nHiddenStatus = cli.pfnGetContactHiddenStatus(hContact, nullptr, dat); if (((style & CLS_SHOWHIDDEN) && nHiddenStatus != -1) || !nHiddenStatus) { ClcCacheEntry *pce = cli.pfnGetCacheEntry(hContact); diff --git a/src/mir_app/src/clistgroups.cpp b/src/mir_app/src/clistgroups.cpp index 9dac871611..8527a131cc 100644 --- a/src/mir_app/src/clistgroups.cpp +++ b/src/mir_app/src/clistgroups.cpp @@ -203,7 +203,7 @@ MIR_APP_DLL(int) Clist_GroupDelete(MGROUP hGroup) szNewParent[0] = '\0'; } - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { ptrW tszGroupName(db_get_wsa(hContact, "CList", "Group")); if (mir_wstrcmp(tszGroupName, pGroup->groupName+1)) continue; @@ -342,7 +342,7 @@ static int RenameGroupWithMove(int groupId, const wchar_t *szName, int move) arByName.insert(pGroup); // must rename setting in all child contacts too - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { ClcCacheEntry *cache = cli.pfnGetCacheEntry(hContact); if (!mir_wstrcmp(cache->tszGroup, oldName)) { db_set_ws(hContact, "CList", "Group", szName); diff --git a/src/mir_app/src/contact.cpp b/src/mir_app/src/contact.cpp index f6b2a7e8ce..d365c01d83 100644 --- a/src/mir_app/src/contact.cpp +++ b/src/mir_app/src/contact.cpp @@ -38,7 +38,7 @@ static int GetContactStatus(MCONTACT hContact) void fnLoadContactTree(void) { int hideOffline = db_get_b(0, "CList", "HideOffline", SETTING_HIDEOFFLINE_DEFAULT); - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { int status = GetContactStatus(hContact); if ((!hideOffline || status != ID_STATUS_OFFLINE) && !db_get_b(hContact, "CList", "Hidden", 0)) cli.pfnChangeContactIcon(hContact, cli.pfnIconFromStatusMode(GetContactProto(hContact), status, hContact)); diff --git a/src/mir_app/src/ignore.cpp b/src/mir_app/src/ignore.cpp index f0c9032a0a..7ee5f1ec7f 100644 --- a/src/mir_app/src/ignore.cpp +++ b/src/mir_app/src/ignore.cpp @@ -172,7 +172,7 @@ static void SaveItemMask(HWND hwndList, MCONTACT hContact, HANDLE hItem, const c static void SetAllContactIcons(HWND hwndList) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0); if (hItem && SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(IGNOREEVENT_MAX, 0)) == EMPTY_EXTRA_ICON) { DWORD proto1Caps, proto4Caps; @@ -297,7 +297,7 @@ static INT_PTR CALLBACK DlgProcIgnoreOpts(HWND hwndDlg, UINT msg, WPARAM, LPARAM case 0: switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_LIST, CLM_FINDCONTACT, hContact, 0); if (hItem) SaveItemMask(GetDlgItem(hwndDlg, IDC_LIST), hContact, hItem, "Mask1"); if (SendDlgItemMessage(hwndDlg, IDC_LIST, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) diff --git a/src/mir_app/src/meta_addto.cpp b/src/mir_app/src/meta_addto.cpp index d3c01aad3f..13adca2900 100644 --- a/src/mir_app/src/meta_addto.cpp +++ b/src/mir_app/src/meta_addto.cpp @@ -43,7 +43,7 @@ static int FillList(HWND list, BOOL sort) int i = 0; // The DB is searched through, to get all the metacontacts - for (MCONTACT hMetaUser = db_find_first(); hMetaUser; hMetaUser = db_find_next(hMetaUser)) { + for (auto &hMetaUser : contact_iter()) { // if it's not a MetaContact, go to the next DBCachedContact *cc = CheckMeta(hMetaUser); if (cc == nullptr) diff --git a/src/mir_app/src/meta_main.cpp b/src/mir_app/src/meta_main.cpp index 9689ba3c93..c8d8824c87 100644 --- a/src/mir_app/src/meta_main.cpp +++ b/src/mir_app/src/meta_main.cpp @@ -77,7 +77,7 @@ int LoadMetacontacts(void) db_set_resident(META_PROTO, "IdleTS"); // set all contacts to 'offline', and initialize subcontact counter for db consistency check - for (MCONTACT hContact = db_find_first(META_PROTO); hContact; hContact = db_find_next(hContact, META_PROTO)) { + for (auto &hContact : contact_iter(META_PROTO)) { db_set_w(hContact, META_PROTO, "Status", ID_STATUS_OFFLINE); db_set_dw(hContact, META_PROTO, "IdleTS", 0); } diff --git a/src/mir_app/src/meta_utils.cpp b/src/mir_app/src/meta_utils.cpp index 1ebeb71319..2c85284f71 100644 --- a/src/mir_app/src/meta_utils.cpp +++ b/src/mir_app/src/meta_utils.cpp @@ -321,7 +321,7 @@ int Meta_HideLinkedContacts(void) DBVARIANT dbv, dbv2; char buffer[512]; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { DBCachedContact *cc = currDb->m_cache->GetCachedContact(hContact); if (cc == nullptr || cc->parentID == 0) continue; @@ -385,7 +385,7 @@ int Meta_HideMetaContacts(bool bHide) // set status suppression bool bSuppress = bHide ? FALSE : g_metaOptions.bSuppressStatus; - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { bool bSet; DBCachedContact *cc = currDb->m_cache->GetCachedContact(hContact); if (cc->IsSub()) { // show on hide, reverse flag @@ -411,7 +411,7 @@ int Meta_HideMetaContacts(bool bHide) int Meta_SuppressStatus(bool suppress) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) if (db_mc_isSub(hContact)) CallService((suppress) ? MS_IGNORE_IGNORE : MS_IGNORE_UNIGNORE, hContact, IGNOREEVENT_USERONLINE); @@ -449,7 +449,7 @@ int Meta_CopyContactNick(DBCachedContact *ccMeta, MCONTACT hContact) int Meta_SetAllNicks() { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { DBCachedContact *cc = CheckMeta(hContact); if (cc == nullptr) continue; diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index a65d30b6a8..8decb6d44b 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -488,3 +488,4 @@ Image_LoadFromMem @505 Image_Resize @506 Image_Save @507 GetDatabasePlugin @508 +?acc_contact_iter@PROTO_INTERFACE@@QBE?AVcontact_iter@@XZ @509 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 2a29d7d486..b09d9d1218 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -488,3 +488,4 @@ Image_LoadFromMem @505 Image_Resize @506 Image_Save @507 GetDatabasePlugin @508 +?acc_contact_iter@PROTO_INTERFACE@@QEBA?AVcontact_iter@@XZ @509 NONAME diff --git a/src/mir_app/src/options_ei.cpp b/src/mir_app/src/options_ei.cpp index 9ac0e0bad4..006272ad62 100644 --- a/src/mir_app/src/options_ei.cpp +++ b/src/mir_app/src/options_ei.cpp @@ -77,7 +77,7 @@ BOOL ScreenToClient(HWND hWnd, LPRECT lpRect) static void RemoveExtraIcons(int slot) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + for (auto &hContact : contact_iter()) Clist_SetExtraIcon(hContact, slot, INVALID_HANDLE_VALUE); } diff --git a/src/mir_app/src/proto_utils.cpp b/src/mir_app/src/proto_utils.cpp index 586b9f330d..e86454b858 100644 --- a/src/mir_app/src/proto_utils.cpp +++ b/src/mir_app/src/proto_utils.cpp @@ -64,7 +64,7 @@ MIR_APP_DLL(INT_PTR) ProtoBroadcastAck(const char *szModule, MCONTACT hContact, void PROTO_INTERFACE::setAllContactStatuses(int iStatus, bool bSkipChats) { - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (isChatRoom(hContact)) { if (!bSkipChats && iStatus == ID_STATUS_OFFLINE) { ptrW wszRoom(getWStringA(hContact, "ChatRoomID")); diff --git a/src/mir_app/src/visibility.cpp b/src/mir_app/src/visibility.cpp index 5946ca3159..e3c13a1c34 100644 --- a/src/mir_app/src/visibility.cpp +++ b/src/mir_app/src/visibility.cpp @@ -100,7 +100,7 @@ static void ResetListOptions(HWND hwndList) static void SetAllContactIcons(HWND hwndList) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0); if (hItem == nullptr) continue; @@ -235,7 +235,7 @@ static INT_PTR CALLBACK DlgProcVisibilityOpts(HWND hwndDlg, UINT msg, WPARAM, LP case 0: if (((LPNMHDR)lParam)->code == PSN_APPLY) { - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (auto &hContact : contact_iter()) { HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_LIST, CLM_FINDCONTACT, hContact, 0); if (hItem == nullptr) continue; -- cgit v1.2.3