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 /protocols/Gadu-Gadu/src/groupchat.cpp | |
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 'protocols/Gadu-Gadu/src/groupchat.cpp')
-rw-r--r-- | protocols/Gadu-Gadu/src/groupchat.cpp | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/protocols/Gadu-Gadu/src/groupchat.cpp b/protocols/Gadu-Gadu/src/groupchat.cpp index 1f19e0c25c..1fd94d1fd1 100644 --- a/protocols/Gadu-Gadu/src/groupchat.cpp +++ b/protocols/Gadu-Gadu/src/groupchat.cpp @@ -137,23 +137,19 @@ int GGPROTO::gc_event(WPARAM wParam, LPARAM lParam) // Window terminated (Miranda exit)
if (gch->pDest->iType == SESSION_TERMINATE)
{
- HANDLE hContact = NULL;
netlog("gc_event(): Terminating chat %x, id %S from chat window...", chat, gch->pDest->ptszID);
// Destroy chat entry
free(chat->recipients);
list_remove(&chats, chat, 1);
+
// Remove contact from contact list (duh!) should be done by chat.dll !!
- hContact = db_find_first();
- while (hContact)
- {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
DBVARIANT dbv;
- if (!db_get_s(hContact, m_szModuleName, "ChatRoomID", &dbv, DBVT_TCHAR))
- {
+ if (!db_get_s(hContact, m_szModuleName, "ChatRoomID", &dbv, DBVT_TCHAR)) {
if (dbv.ptszVal && !_tcscmp(gch->pDest->ptszID, dbv.ptszVal))
CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0);
db_free(&dbv);
}
- hContact = db_find_next(hContact);
}
return 1;
}
@@ -440,13 +436,10 @@ static void gg_gc_resetclistopts(HWND hwndList) static int gg_gc_countcheckmarks(HWND hwndList)
{
int count = 0;
- HANDLE hItem, hContact = db_find_first();
- while (hContact)
- {
- hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, (WPARAM)hContact, 0);
+ 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_GETCHECKMARK, (WPARAM)hItem, 0))
count++;
- hContact = db_find_next(hContact);
}
return count;
}
@@ -494,17 +487,13 @@ static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wPa // Create new participiants table
TCHAR* chat;
uin_t* participants = (uin_t*)calloc(count, sizeof(uin_t));
- HANDLE hItem, hContact = db_find_first();
gg->netlog("gg_gc_openconfdlg(): WM_COMMAND IDOK Opening new conference for %d contacts.", count);
- while (hContact && i < count)
- {
- hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, (WPARAM)hContact, 0);
- if (hItem && SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)hItem, 0))
- {
+ for (HANDLE hContact = db_find_first(); hContact && i < count; hContact = db_find_next(hContact)) {
+ HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, (WPARAM)hContact, 0);
+ if (hItem && SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) {
HANDLE hMetaContact = gg_getsubcontact(gg, hContact); // MetaContacts support
participants[i++] = db_get_dw(hMetaContact ? hMetaContact : hContact, gg->m_szModuleName, GG_KEY_UIN, 0);
}
- hContact = db_find_next(hContact);
}
if (count > i) i = count;
chat = gg->gc_getchat(0, participants, count);
@@ -545,8 +534,6 @@ static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wPa case CLN_CONTACTMOVED:
case CLN_LISTREBUILT:
{
- HANDLE hContact;
- HANDLE hItem;
char* szProto;
uin_t uin;
GGPROTO* gg = (GGPROTO*)GetWindowLongPtr(hwndDlg, DWLP_USER);
@@ -554,20 +541,15 @@ static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wPa if (!gg) break;
// Delete non-gg contacts
- hContact = db_find_first();
- while (hContact)
- {
- hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, (WPARAM)hContact, 0);
- if (hItem)
- {
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, (WPARAM)hContact, 0);
+ if (hItem) {
HANDLE hMetaContact = gg_getsubcontact(gg, hContact); // MetaContacts support
- if (hMetaContact)
- {
+ if (hMetaContact) {
szProto = gg->m_szModuleName;
uin = (uin_t)db_get_dw(hMetaContact, gg->m_szModuleName, GG_KEY_UIN, 0);
}
- else
- {
+ else {
szProto = GetContactProto(hContact);
uin = (uin_t)db_get_dw(hContact, gg->m_szModuleName, GG_KEY_UIN, 0);
}
@@ -575,7 +557,6 @@ static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wPa if (szProto == NULL || lstrcmpA(szProto, gg->m_szModuleName) || !uin || uin == db_get_dw(NULL, gg->m_szModuleName, GG_KEY_UIN, 0))
SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_DELETEITEM, (WPARAM)hItem, 0);
}
- hContact = db_find_next(hContact);
}
}
break;
|