diff options
author | George Hazan <george.hazan@gmail.com> | 2013-04-09 20:03:46 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-04-09 20:03:46 +0000 |
commit | bcb27264ba737778e5d3edad36088bacf74f0236 (patch) | |
tree | fd1f57744dd380b7babe312a0ab5dc60b48854f2 /src/modules | |
parent | 940231dc5a484b03a278900e1880aa083472b601 (diff) |
- 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
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/clist/clcitems.cpp | 39 | ||||
-rw-r--r-- | src/modules/clist/clistmod.cpp | 4 | ||||
-rw-r--r-- | src/modules/clist/contact.cpp | 13 | ||||
-rw-r--r-- | src/modules/clist/groups.cpp | 13 | ||||
-rw-r--r-- | src/modules/extraicons/DefaultExtraIcons.cpp | 5 | ||||
-rw-r--r-- | src/modules/extraicons/ExtraIcon.cpp | 7 | ||||
-rw-r--r-- | src/modules/extraicons/extraicons.cpp | 9 | ||||
-rw-r--r-- | src/modules/extraicons/options_ei.cpp | 5 | ||||
-rw-r--r-- | src/modules/ignore/ignore.cpp | 40 | ||||
-rw-r--r-- | src/modules/visibility/visibility.cpp | 8 |
10 files changed, 46 insertions, 97 deletions
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
{
diff --git a/src/modules/extraicons/DefaultExtraIcons.cpp b/src/modules/extraicons/DefaultExtraIcons.cpp index 590d21c715..3287a72d1d 100644 --- a/src/modules/extraicons/DefaultExtraIcons.cpp +++ b/src/modules/extraicons/DefaultExtraIcons.cpp @@ -342,13 +342,10 @@ void DefaultExtraIcons_Load() p.hExtraIcon = ExtraIcon_Register(p.name, p.desc, LoadSkinnedIconName(p.iSkinIcon));
}
- HANDLE hContact = db_find_first();
- while (hContact != NULL) {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
SetExtraIcons(hContact);
SetVisibility(hContact, -1, false);
SetGender(hContact, -1, false);
-
- hContact = db_find_next(hContact);
}
HookEvent(ME_DB_CONTACT_SETTINGCHANGED, SettingChanged);
diff --git a/src/modules/extraicons/ExtraIcon.cpp b/src/modules/extraicons/ExtraIcon.cpp index f59a7310fa..379265e9ba 100644 --- a/src/modules/extraicons/ExtraIcon.cpp +++ b/src/modules/extraicons/ExtraIcon.cpp @@ -67,15 +67,10 @@ void ExtraIcon::applyIcons() if (!isEnabled())
return;
- HANDLE hContact = db_find_first();
- while (hContact != NULL)
- {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
// Clear to assert that it will be cleared
Clist_SetExtraIcon(hContact, slot, INVALID_HANDLE_VALUE);
-
applyIcon(hContact);
-
- hContact = db_find_next(hContact);
}
}
diff --git a/src/modules/extraicons/extraicons.cpp b/src/modules/extraicons/extraicons.cpp index 24cec55b7f..79922167c4 100644 --- a/src/modules/extraicons/extraicons.cpp +++ b/src/modules/extraicons/extraicons.cpp @@ -330,12 +330,8 @@ void fnSetAllExtraIcons(HWND hwndList, HANDLE hContact) if (hContact == NULL)
hContact = db_find_first();
- do {
- HANDLE hItem = hContact;
- if (hItem == 0)
- continue;
-
- ClcCacheEntry* pdnce = (ClcCacheEntry*)cli.pfnGetCacheEntry(hItem);
+ for (; hContact; hContact = db_find_next(hContact)) {
+ ClcCacheEntry* pdnce = (ClcCacheEntry*)cli.pfnGetCacheEntry(hContact);
if (pdnce == NULL)
continue;
@@ -343,7 +339,6 @@ void fnSetAllExtraIcons(HWND hwndList, HANDLE hContact) if (hcontgiven) break;
Sleep(0);
}
- while(hContact = db_find_next(hContact));
g_mutex_bSetAllExtraIconsCycle = 0;
cli.pfnInvalidateRect(hwndList, NULL, FALSE);
diff --git a/src/modules/extraicons/options_ei.cpp b/src/modules/extraicons/options_ei.cpp index 99d5f8c91d..48a763dc83 100644 --- a/src/modules/extraicons/options_ei.cpp +++ b/src/modules/extraicons/options_ei.cpp @@ -56,11 +56,8 @@ BOOL ScreenToClient(HWND hWnd, LPRECT lpRect) static void RemoveExtraIcons(int slot)
{
- HANDLE hContact = db_find_first();
- while (hContact != NULL) {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
Clist_SetExtraIcon(hContact, slot, INVALID_HANDLE_VALUE);
- hContact = db_find_next(hContact);
- }
}
#ifndef TVIS_FOCUSED
diff --git a/src/modules/ignore/ignore.cpp b/src/modules/ignore/ignore.cpp index e77f0e6321..d719ca67a8 100644 --- a/src/modules/ignore/ignore.cpp +++ b/src/modules/ignore/ignore.cpp @@ -168,8 +168,7 @@ static void SaveItemMask(HWND hwndList, HANDLE hContact, HANDLE hItem, const cha static void SetAllContactIcons(HWND hwndList)
{
- HANDLE hContact = db_find_first();
- do {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, (WPARAM)hContact, 0);
if (hItem && SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(IGNOREEVENT_MAX, 0)) == EMPTY_EXTRA_ICON) {
DWORD proto1Caps, proto4Caps;
@@ -184,7 +183,6 @@ static void SetAllContactIcons(HWND hwndList) SendMessage(hwndList, CLM_SETCHECKMARK, (WPARAM)hItem, 1);
}
}
- while (hContact = db_find_next(hContact));
}
static INT_PTR CALLBACK DlgProcIgnoreOpts(HWND hwndDlg, UINT msg, WPARAM, LPARAM lParam)
@@ -291,41 +289,33 @@ static INT_PTR CALLBACK DlgProcIgnoreOpts(HWND hwndDlg, UINT msg, WPARAM, LPARAM SetListGroupIcons( GetDlgItem(hwndDlg, IDC_LIST), (HANDLE)SendDlgItemMessage(hwndDlg, IDC_LIST, CLM_GETNEXTITEM, CLGN_ROOT, 0), hItemAll, NULL);
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
}
- break;
}
break;
case 0:
switch (((LPNMHDR)lParam)->code) {
case PSN_APPLY:
- {
- HANDLE hContact = db_find_first();
- do {
- HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_LIST, CLM_FINDCONTACT, (WPARAM)hContact, 0);
- if (hItem) SaveItemMask( GetDlgItem(hwndDlg, IDC_LIST), hContact, hItem, "Mask1");
- if (SendDlgItemMessage(hwndDlg, IDC_LIST, CLM_GETCHECKMARK, (WPARAM)hItem, 0))
- db_unset(hContact, "CList", "Hidden");
- else
- db_set_b(hContact, "CList", "Hidden", 1);
- }
- while (hContact = db_find_next(hContact));
- SaveItemMask( GetDlgItem(hwndDlg, IDC_LIST), NULL, hItemAll, "Default1");
- SaveItemMask( GetDlgItem(hwndDlg, IDC_LIST), NULL, hItemUnknown, "Mask1");
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_LIST, CLM_FINDCONTACT, (WPARAM)hContact, 0);
+ if (hItem) SaveItemMask( GetDlgItem(hwndDlg, IDC_LIST), hContact, hItem, "Mask1");
+ if (SendDlgItemMessage(hwndDlg, IDC_LIST, CLM_GETCHECKMARK, (WPARAM)hItem, 0))
+ db_unset(hContact, "CList", "Hidden");
+ else
+ db_set_b(hContact, "CList", "Hidden", 1);
}
- return TRUE;
+ SaveItemMask( GetDlgItem(hwndDlg, IDC_LIST), NULL, hItemAll, "Default1");
+ SaveItemMask( GetDlgItem(hwndDlg, IDC_LIST), NULL, hItemUnknown, "Mask1");
+ return TRUE;
}
- break;
}
break;
case WM_DESTROY:
- {
- for (int i=0; i < SIZEOF(hIcons); i++)
- DestroyIcon(hIcons[i]);
- HIMAGELIST hIml = (HIMAGELIST)SendDlgItemMessage(hwndDlg, IDC_LIST, CLM_GETEXTRAIMAGELIST, 0, 0);
- ImageList_Destroy(hIml);
- }
+ for (int i=0; i < SIZEOF(hIcons); i++)
+ DestroyIcon(hIcons[i]);
+ HIMAGELIST hIml = (HIMAGELIST)SendDlgItemMessage(hwndDlg, IDC_LIST, CLM_GETEXTRAIMAGELIST, 0, 0);
+ ImageList_Destroy(hIml);
break;
}
return FALSE;
diff --git a/src/modules/visibility/visibility.cpp b/src/modules/visibility/visibility.cpp index b8b21b2838..5204a0a622 100644 --- a/src/modules/visibility/visibility.cpp +++ b/src/modules/visibility/visibility.cpp @@ -106,8 +106,7 @@ static void ResetListOptions(HWND hwndList) static void SetAllContactIcons(HWND hwndList)
{
- HANDLE hContact = db_find_first();
- do {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, (WPARAM)hContact, 0);
if (hItem) {
DWORD flags;
@@ -131,7 +130,6 @@ static void SetAllContactIcons(HWND hwndList) SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(1, status == ID_STATUS_OFFLINE ? 2 : 0));
}
}
- while (hContact = db_find_next(hContact));
}
static INT_PTR CALLBACK DlgProcVisibilityOpts(HWND hwndDlg, UINT msg, WPARAM, LPARAM lParam)
@@ -244,8 +242,7 @@ static INT_PTR CALLBACK DlgProcVisibilityOpts(HWND hwndDlg, UINT msg, WPARAM, LP case 0:
if (((LPNMHDR)lParam)->code == PSN_APPLY) {
- HANDLE hContact = db_find_first();
- do {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_LIST, CLM_FINDCONTACT, (WPARAM)hContact, 0);
if (hItem) {
int set = 0;
@@ -261,7 +258,6 @@ static INT_PTR CALLBACK DlgProcVisibilityOpts(HWND hwndDlg, UINT msg, WPARAM, LP CallContactService(hContact, PSS_SETAPPARENTMODE, 0, 0);
}
}
- while (hContact = db_find_next(hContact));
return TRUE;
}
}
|