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 --- protocols/Gadu-Gadu/src/core.cpp | 38 ++++++++++------------------- protocols/Gadu-Gadu/src/groupchat.cpp | 45 ++++++++++------------------------- protocols/Gadu-Gadu/src/import.cpp | 12 ++++------ 3 files changed, 30 insertions(+), 65 deletions(-) (limited to 'protocols/Gadu-Gadu/src') diff --git a/protocols/Gadu-Gadu/src/core.cpp b/protocols/Gadu-Gadu/src/core.cpp index 6d3b91fe28..393157275d 100644 --- a/protocols/Gadu-Gadu/src/core.cpp +++ b/protocols/Gadu-Gadu/src/core.cpp @@ -1446,12 +1446,10 @@ void GGPROTO::setalloffline() { netlog("setalloffline(): started. Setting buddies offline"); db_set_w(NULL, m_szModuleName, GG_KEY_STATUS, ID_STATUS_OFFLINE); - 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, m_szModuleName)) - { + if (szProto != NULL && !strcmp(szProto, m_szModuleName)) { db_set_w(hContact, m_szModuleName, GG_KEY_STATUS, ID_STATUS_OFFLINE); // Clear IP and port settings db_unset(hContact, m_szModuleName, GG_KEY_CLIENTIP); @@ -1459,7 +1457,6 @@ void GGPROTO::setalloffline() // Delete status descr db_unset(hContact, "CList", GG_KEY_STATUSDESCR); } - hContact = db_find_next(hContact); } #ifdef DEBUGMODE netlog("setalloffline(): End."); @@ -1519,20 +1516,17 @@ void GGPROTO::notifyall() netlog("notifyall(): Subscribing notification to all users"); // Readup count - hContact = db_find_first(); - while (hContact) - { + + for (hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { szProto = GetContactProto(hContact); - if (szProto != NULL && !strcmp(szProto, m_szModuleName)) count ++; - hContact = db_find_next(hContact); + if (szProto != NULL && !strcmp(szProto, m_szModuleName)) + count ++; } // Readup list /* FIXME: If we have nothing on the list but we omit gg_notify_ex we have problem with receiving any contacts */ - if (count == 0) - { - if (isonline()) - { + if (count == 0) { + if (isonline()) { gg_EnterCriticalSection(&sess_mutex, "notifyall", 29, "sess_mutex", 1); gg_notify_ex(sess, NULL, NULL, 0); gg_LeaveCriticalSection(&sess_mutex, "notifyall", 29, 1, "sess_mutex", 1); @@ -1542,12 +1536,9 @@ void GGPROTO::notifyall() uins = (uin_t*)calloc(sizeof(uin_t), count); types = (char*)calloc(sizeof(char), count); - hContact = db_find_first(); - while (hContact && cc < count) - { + for (hContact = db_find_first(); hContact && cc < count; hContact = db_find_next(hContact)) { szProto = GetContactProto(hContact); - if (szProto != NULL && !strcmp(szProto, m_szModuleName) && (uins[cc] = db_get_dw(hContact, m_szModuleName, GG_KEY_UIN, 0))) - { + if (szProto != NULL && !strcmp(szProto, m_szModuleName) && (uins[cc] = db_get_dw(hContact, m_szModuleName, GG_KEY_UIN, 0))) { if ((db_get_w(hContact, m_szModuleName, GG_KEY_APPARENT, (WORD) ID_STATUS_ONLINE) == ID_STATUS_OFFLINE) || db_get_b(hContact, "CList", "NotOnList", 0)) types[cc] = GG_USER_OFFLINE; @@ -1557,7 +1548,6 @@ void GGPROTO::notifyall() types[cc] = GG_USER_NORMAL; cc ++; } - hContact = db_find_next(hContact); } if (cc < count) count = cc; @@ -1582,8 +1572,7 @@ HANDLE GGPROTO::getcontact(uin_t uin, int create, int inlist, TCHAR *szNick) netlog("getcontact(): uin=%d create=%d inlist=%d", uin, create, inlist); #endif // Look for contact in DB - 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, m_szModuleName)) { if ((uin_t)db_get_dw(hContact, m_szModuleName, GG_KEY_UIN, 0) == uin @@ -1596,11 +1585,10 @@ HANDLE GGPROTO::getcontact(uin_t uin, int create, int inlist, TCHAR *szNick) return hContact; } } - hContact = db_find_next(hContact); } if (!create) return NULL; - hContact = (HANDLE) CallService(MS_DB_CONTACT_ADD, 0, 0); + HANDLE hContact = (HANDLE) CallService(MS_DB_CONTACT_ADD, 0, 0); if (!hContact) { netlog("getcontact(): Failed to create Gadu-Gadu contact %S", szNick); return NULL; 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; diff --git a/protocols/Gadu-Gadu/src/import.cpp b/protocols/Gadu-Gadu/src/import.cpp index abaa9799f6..0492ecb32b 100644 --- a/protocols/Gadu-Gadu/src/import.cpp +++ b/protocols/Gadu-Gadu/src/import.cpp @@ -101,12 +101,9 @@ char *gg_makecontacts(GGPROTO *gg, int cr) char *contacts; // Readup contacts - 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, gg->m_szModuleName) && !db_get_b(hContact, gg->m_szModuleName, "ChatRoom", 0)) - { + if (szProto != NULL && !strcmp(szProto, gg->m_szModuleName) && !db_get_b(hContact, gg->m_szModuleName, "ChatRoom", 0)) { DBVARIANT dbv; // Readup FirstName @@ -139,9 +136,9 @@ char *gg_makecontacts(GGPROTO *gg, int cr) string_append(s, pszValA); mir_free(pszValA); db_free(&dbv2); - } else { - string_append(s, dbvA); } + else string_append(s, dbvA); + string_append_c(s, ';'); string_append(s, dbvA); mir_free(dbvA); @@ -183,7 +180,6 @@ char *gg_makecontacts(GGPROTO *gg, int cr) else string_append(s, ";0;;0;\n"); } - hContact = db_find_next(hContact); } contacts = string_free(s, 0); -- cgit v1.2.3