From bcb27264ba737778e5d3edad36088bacf74f0236 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 9 Apr 2013 20:03:46 +0000 Subject: - short function names allows to write database loops in one string; - 'continue' operator can be used then; - multiple bugs fixed in clists; - code becomes much more compact; git-svn-id: http://svn.miranda-ng.org/main/trunk@4403 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/modules/clist/clcitems.cpp | 39 +++++++++++++++------------------------ src/modules/clist/clistmod.cpp | 4 +--- src/modules/clist/contact.cpp | 13 ++++--------- src/modules/clist/groups.cpp | 13 ++++--------- 4 files changed, 24 insertions(+), 45 deletions(-) (limited to 'src/modules/clist') diff --git a/src/modules/clist/clcitems.cpp b/src/modules/clist/clcitems.cpp index f2e6dac894..139c7e6e70 100644 --- a/src/modules/clist/clcitems.cpp +++ b/src/modules/clist/clcitems.cpp @@ -107,17 +107,15 @@ ClcGroup* fnAddGroup(HWND hwnd, struct ClcData *dat, const TCHAR *szName, DWORD group->totalMembers = 0; if (flags != (DWORD) - 1 && pNextField == NULL && calcTotalMembers) { DWORD style = GetWindowLongPtr(hwnd, GWL_STYLE); - HANDLE hContact = db_find_first(); - while (hContact) { - ClcCacheEntry* cache = cli.pfnGetCacheEntry(hContact); + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + ClcCacheEntry *cache = cli.pfnGetCacheEntry(hContact); if ( !lstrcmp(cache->tszGroup, szName) && (style & CLS_SHOWHIDDEN || !cache->bIsHidden)) group->totalMembers++; - - hContact = db_find_next(hContact); } } } - } while (pNextField); + } + while (pNextField); return group; } @@ -348,32 +346,25 @@ void fnDeleteItemFromTree(HWND hwnd, HANDLE hItem) void fnRebuildEntireList(HWND hwnd, struct ClcData *dat) { - char *szProto; DWORD style = GetWindowLongPtr(hwnd, GWL_STYLE); - HANDLE hContact; ClcGroup *group; - DBVARIANT dbv; dat->list.expanded = 1; dat->list.hideOffline = db_get_b(NULL, "CLC", "HideOfflineRoot", 0) && style&CLS_USEGROUPS; dat->list.cl.count = dat->list.cl.limit = 0; dat->selection = -1; - { - int i; - TCHAR *szGroupName; - DWORD groupFlags; - for (i = 1;; i++) { - szGroupName = cli.pfnGetGroupName(i, &groupFlags); - if (szGroupName == NULL) - break; - cli.pfnAddGroup(hwnd, dat, szGroupName, groupFlags, i, 0); - } + for (int i = 1;; i++) { + DWORD groupFlags; + TCHAR *szGroupName = cli.pfnGetGroupName(i, &groupFlags); + if (szGroupName == NULL) + break; + cli.pfnAddGroup(hwnd, dat, szGroupName, groupFlags, i, 0); } - hContact = db_find_first(); - while (hContact) { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { if (style & CLS_SHOWHIDDEN || !db_get_b(hContact, "CList", "Hidden", 0)) { + DBVARIANT dbv; if (db_get_ts(hContact, "CList", "Group", &dbv)) group = &dat->list; else { @@ -392,8 +383,9 @@ void fnRebuildEntireList(HWND hwnd, struct ClcData *dat) if (_tcsstr(lowered_name, lowered_search)) cli.pfnAddContactToGroup(dat, group, hContact); - } else if ( !(style & CLS_NOHIDEOFFLINE) && (style & CLS_HIDEOFFLINE || group->hideOffline)) { - szProto = GetContactProto(hContact); + } + else if ( !(style & CLS_NOHIDEOFFLINE) && (style & CLS_HIDEOFFLINE || group->hideOffline)) { + char *szProto = GetContactProto(hContact); if (szProto == NULL) { if ( !cli.pfnIsHiddenMode(dat, ID_STATUS_OFFLINE)) cli.pfnAddContactToGroup(dat, group, hContact); @@ -404,7 +396,6 @@ void fnRebuildEntireList(HWND hwnd, struct ClcData *dat) else cli.pfnAddContactToGroup(dat, group, hContact); } } - hContact = db_find_next(hContact); } if (style & CLS_HIDEEMPTYGROUPS) { diff --git a/src/modules/clist/clistmod.cpp b/src/modules/clist/clistmod.cpp index 65b1b7eebf..3b3797a90e 100644 --- a/src/modules/clist/clistmod.cpp +++ b/src/modules/clist/clistmod.cpp @@ -144,13 +144,11 @@ static int ProtocolAck(WPARAM, LPARAM lParam) if ((int)ack->hProcess < ID_STATUS_ONLINE && ack->lParam >= ID_STATUS_ONLINE) { DWORD caps = (DWORD)CallProtoServiceInt(NULL,ack->szModule, PS_GETCAPS, PFLAGNUM_1, 0); if (caps & PF1_SERVERCLIST) { - HANDLE hContact = db_find_first(); - while (hContact) { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { char *szProto = GetContactProto(hContact); if (szProto != NULL && !strcmp(szProto, ack->szModule)) if (db_get_b(hContact, "CList", "Delete", 0)) CallService(MS_DB_CONTACT_DELETE, (WPARAM) hContact, 0); - hContact = db_find_next(hContact); } } } diff --git a/src/modules/clist/contact.cpp b/src/modules/clist/contact.cpp index 209f8fc052..7671cd2b11 100644 --- a/src/modules/clist/contact.cpp +++ b/src/modules/clist/contact.cpp @@ -69,23 +69,18 @@ int GetStatusModeOrdering(int statusMode) void fnLoadContactTree(void) { - HANDLE hContact; - int i, status, hideOffline; - CallService(MS_CLUI_LISTBEGINREBUILD, 0, 0); - for (i = 1;; i++) { + for (int i = 1;; i++) { if (cli.pfnGetGroupName(i, NULL) == NULL) break; CallService(MS_CLUI_GROUPADDED, i, 0); } - hideOffline = db_get_b(NULL, "CList", "HideOffline", SETTING_HIDEOFFLINE_DEFAULT); - hContact = db_find_first(); - while (hContact != NULL) { - status = GetContactStatus(hContact); + int hideOffline = db_get_b(NULL, "CList", "HideOffline", SETTING_HIDEOFFLINE_DEFAULT); + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + 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), 1); - hContact = db_find_next(hContact); } sortByStatus = db_get_b(NULL, "CList", "SortByStatus", SETTING_SORTBYSTATUS_DEFAULT); sortByProto = db_get_b(NULL, "CList", "SortByProto", SETTING_SORTBYPROTO_DEFAULT); diff --git a/src/modules/clist/groups.cpp b/src/modules/clist/groups.cpp index eb221ae5c7..c2ac366c54 100644 --- a/src/modules/clist/groups.cpp +++ b/src/modules/clist/groups.cpp @@ -184,10 +184,7 @@ static INT_PTR DeleteGroup(WPARAM wParam, LPARAM) CLISTGROUPCHANGE grpChg = { sizeof(CLISTGROUPCHANGE), NULL, NULL }; - for (hContact = db_find_first(); - hContact; - hContact = db_find_next(hContact)) - { + for (hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { if (db_get_ts(hContact, "CList", "Group", &dbv)) continue; @@ -256,7 +253,6 @@ static int RenameGroupWithMove(int groupId, const TCHAR *szName, int move) char idstr[33]; TCHAR str[256], oldName[256]; DBVARIANT dbv; - HANDLE hContact; if (GroupNameExists(szName, groupId)) { MessageBox(NULL, TranslateT("You already have a group with that name. Please enter a unique name for the group."), TranslateT("Rename Group"), MB_OK); @@ -274,16 +270,15 @@ static int RenameGroupWithMove(int groupId, const TCHAR *szName, int move) db_set_ts(NULL, "CListGroups", idstr, str); //must rename setting in all child contacts too - hContact = db_find_first(); - do { - ClcCacheEntry* cache = cli.pfnGetCacheEntry(hContact); + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + ClcCacheEntry *cache = cli.pfnGetCacheEntry(hContact); if ( !lstrcmp(cache->tszGroup, oldName)) { db_set_ts(hContact, "CList", "Group", szName); mir_free(cache->tszGroup); cache->tszGroup = 0; cli.pfnCheckCacheItem(cache); } - } while ((hContact = db_find_next(hContact)) != NULL); + } //rename subgroups { -- cgit v1.2.3