From 4262e8021c8ffdc0401d9ebe09899f90c654aa18 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 30 Apr 2021 11:37:17 +0300 Subject: we use contact iterators when possible --- plugins/DbEditorPP/src/exportimport.cpp | 25 ++++++++-------------- plugins/DbEditorPP/src/main_window.cpp | 3 +-- plugins/MirandaG15/src/CContactList.cpp | 9 +++----- plugins/UserInfoEx/src/dlg_propsheet.cpp | 5 +++-- .../UserInfoEx/src/ex_import/dlg_ExImModules.cpp | 4 +--- plugins/UserInfoEx/src/ex_import/svc_ExImINI.cpp | 2 +- plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp | 2 +- 7 files changed, 19 insertions(+), 31 deletions(-) (limited to 'plugins') diff --git a/plugins/DbEditorPP/src/exportimport.cpp b/plugins/DbEditorPP/src/exportimport.cpp index a182418881..4ae33f26d1 100644 --- a/plugins/DbEditorPP/src/exportimport.cpp +++ b/plugins/DbEditorPP/src/exportimport.cpp @@ -161,17 +161,15 @@ void exportDB(MCONTACT hContact, const char *module) // exporting entire db if (hContact == INVALID_CONTACT_ID) { - hContact = NULL; - if (module == nullptr) { fprintf(file, "SETTINGS:\n"); mod = modlist.first; while (mod) { - if (IsModuleEmpty(hContact, mod->name)) { + if (IsModuleEmpty(NULL, mod->name)) { mod = (ModSetLinkLinkItem *)mod->next; continue; } - exportModule(hContact, mod->name, file); + exportModule(NULL, mod->name, file); mod = (ModSetLinkLinkItem *)mod->next; if (mod) fprintf(file, "\n"); @@ -182,27 +180,23 @@ void exportDB(MCONTACT hContact, const char *module) module = nullptr; // reset module for all contacts export } - hContact = db_find_first(); - if (hContact) - fprintf(file, "\n\n"); + fprintf(file, "\n\n"); - while (hContact) { - if (ApplyProtoFilter(hContact)) { - hContact = db_find_next(hContact); + for (auto &cc : Contacts()) { + if (ApplyProtoFilter(cc)) continue; - } - fprintf(file, "CONTACT: %s\n", NickFromHContact(hContact)); + fprintf(file, "CONTACT: %s\n", NickFromHContact(cc)); if (module == nullptr) // export all modules { mod = modlist.first; while (mod) { - if (IsModuleEmpty(hContact, mod->name)) { + if (IsModuleEmpty(cc, mod->name)) { mod = (ModSetLinkLinkItem *)mod->next; continue; } - exportModule(hContact, mod->name, file); + exportModule(cc, mod->name, file); mod = (ModSetLinkLinkItem *)mod->next; if (mod) fprintf(file, "\n"); @@ -210,9 +204,8 @@ void exportDB(MCONTACT hContact, const char *module) } else // export module { - exportModule(hContact, module, file); + exportModule(cc, module, file); } - hContact = db_find_next(hContact); } } // exporting a contact diff --git a/plugins/DbEditorPP/src/main_window.cpp b/plugins/DbEditorPP/src/main_window.cpp index a281640f1f..4eb8e0e128 100644 --- a/plugins/DbEditorPP/src/main_window.cpp +++ b/plugins/DbEditorPP/src/main_window.cpp @@ -555,8 +555,7 @@ void CMainDlg::onSelChanged_Modules(CCtrlTreeView::TEventInfo *ev) Select = 0; if (mtis->type == MODULE) { - _T2A module(text); - PopulateSettings(hContact, module); + PopulateSettings(hContact, _T2A(text)); } else if (((mtis->type & CONTACT) == CONTACT && hContact) || (mtis->type == CONTACT_ROOT_ITEM && !hContact)) { int multi = 0; diff --git a/plugins/MirandaG15/src/CContactList.cpp b/plugins/MirandaG15/src/CContactList.cpp index 06592a2ce5..872c3570a2 100644 --- a/plugins/MirandaG15/src/CContactList.cpp +++ b/plugins/MirandaG15/src/CContactList.cpp @@ -506,15 +506,12 @@ void CContactList::RefreshList() m_bUseGroups = CConfig::GetBoolSetting(CLIST_USEGROUPS); m_bUseMetaContacts = db_get_b(0, "MetaContacts", "Enabled", 1) != 0; - CListEntry *pContactEntry = nullptr; - MCONTACT hContact = db_find_first(); - while (hContact != NULL) { - pContactEntry = FindContact(hContact); + for (auto &hContact: Contacts()) { + auto *pContactEntry = FindContact(hContact); if (!pContactEntry) AddContact(hContact); else if (pContactEntry && !IsVisible(GetContactData(pContactEntry))) RemoveContact(hContact); - hContact = db_find_next(hContact); } } @@ -935,7 +932,7 @@ void CContactList::InitializeGroupObjects() { UninitializeGroupObjects(); - for (MCONTACT hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) { + for (auto &hContact: Contacts()) { tstring strGroup = GetContactGroupPath(hContact); char *szProto = Proto_GetBaseAccountName(hContact); if (szProto && db_get_b(0, META_PROTO, "Enabled", 1) && !mir_strcmpi(szProto, META_PROTO)) { diff --git a/plugins/UserInfoEx/src/dlg_propsheet.cpp b/plugins/UserInfoEx/src/dlg_propsheet.cpp index e61f5e1e93..4267b8ab0e 100644 --- a/plugins/UserInfoEx/src/dlg_propsheet.cpp +++ b/plugins/UserInfoEx/src/dlg_propsheet.cpp @@ -494,11 +494,12 @@ void DlgContactInfoInitTreeIcons() // enumerate all protocols for (auto &pa : Accounts()) { // enumerate all contacts - for (psh._hContact = db_find_first(); psh._hContact != NULL; psh._hContact = db_find_next(psh._hContact)) { + for (auto &cc: Contacts(pa->szModuleName)) { // compare contact's protocol to the current one, to add - LPCSTR pszContactProto = Proto_GetBaseAccountName(psh._hContact); + LPCSTR pszContactProto = Proto_GetBaseAccountName(cc); if ((INT_PTR)pszContactProto != CALLSERVICE_NOTFOUND && !mir_strcmp(pa->szModuleName, pszContactProto)) { // call a notification for the contact to retrieve all protocol specific tree items + psh._hContact = cc; NotifyEventHooks(g_hDetailsInitEvent, (WPARAM)&psh, (LPARAM)psh._hContact); if (psh._pPages) { psh.Free_pPages(); diff --git a/plugins/UserInfoEx/src/ex_import/dlg_ExImModules.cpp b/plugins/UserInfoEx/src/ex_import/dlg_ExImModules.cpp index 945d404c2b..ec1cb4b629 100644 --- a/plugins/UserInfoEx/src/ex_import/dlg_ExImModules.cpp +++ b/plugins/UserInfoEx/src/ex_import/dlg_ExImModules.cpp @@ -273,9 +273,7 @@ INT_PTR CALLBACK SelectModulesToExport_DlgProc(HWND hDlg, UINT uMsg, WPARAM wPar // module must exist in at least one contact if (pDat->ExImContact->Typ != EXIM_CONTACT) // TRUE = All Contacts { - MCONTACT hContact; - - for (hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) { + for (auto &hContact: Contacts()) { // ignore empty modules if (!DB::Module::IsEmpty(hContact, p)) { pszProto = Proto_GetBaseAccountName(hContact); diff --git a/plugins/UserInfoEx/src/ex_import/svc_ExImINI.cpp b/plugins/UserInfoEx/src/ex_import/svc_ExImINI.cpp index dc826a7139..a83438b9ad 100644 --- a/plugins/UserInfoEx/src/ex_import/svc_ExImINI.cpp +++ b/plugins/UserInfoEx/src/ex_import/svc_ExImINI.cpp @@ -158,7 +158,7 @@ int SvcExImINI_Export(lpExImParam ExImContact, const wchar_t *pszFileName) ExportContact(NULL, &Modules, file); fprintf(file, "\n\n"); // Contacts - for (MCONTACT hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) { + for (auto &hContact: Contacts()) { ExportContact(hContact, &Modules, file); fprintf(file, "\n\n"); } diff --git a/plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp b/plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp index 3022575e8e..09e8040a50 100644 --- a/plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp +++ b/plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp @@ -137,7 +137,7 @@ int CFileXml::Export(lpExImParam ExImContact, const wchar_t *pszFileName) vContact.Export(xmlfile, &Modules); // loop for all other contact - for (MCONTACT hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) { + for (auto &hContact: Contacts()) { switch (ExImContact->Typ) { case EXIM_ALL: case EXIM_GROUP: -- cgit v1.2.3