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/AimOscar/src/theme.cpp | 24 ++-------- protocols/AimOscar/src/utility.cpp | 89 +++++++++++--------------------------- 2 files changed, 30 insertions(+), 83 deletions(-) (limited to 'protocols/AimOscar') diff --git a/protocols/AimOscar/src/theme.cpp b/protocols/AimOscar/src/theme.cpp index b5c0ae20a7..3dc5dce55f 100644 --- a/protocols/AimOscar/src/theme.cpp +++ b/protocols/AimOscar/src/theme.cpp @@ -144,46 +144,30 @@ void set_contact_icon(CAimProto* ppro, HANDLE hContact) void remove_AT_icons(CAimProto* ppro) { - HANDLE hContact = db_find_first(); - while (hContact) { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) if (ppro->is_my_contact(hContact) && !ppro->getByte(hContact, "ChatRoom", 0)) ExtraIcon_Clear(hExtraAT, hContact); - - hContact = db_find_next(hContact); - } } void remove_ES_icons(CAimProto* ppro) { - HANDLE hContact = db_find_first(); - while (hContact) { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) if (ppro->is_my_contact(hContact) && !ppro->getByte(hContact, "ChatRoom", 0)) ExtraIcon_Clear(hExtraES, hContact); - - hContact = db_find_next(hContact); - } } void add_AT_icons(CAimProto* ppro) { - HANDLE hContact = db_find_first(); - while (hContact) { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) if (ppro->is_my_contact(hContact)) set_AT_icon(ppro, hContact); - - hContact = db_find_next(hContact); - } } void add_ES_icons(CAimProto* ppro) { - HANDLE hContact = db_find_first(); - while (hContact) { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) if (ppro->is_my_contact(hContact)) set_ES_icon(ppro, hContact); - - hContact = db_find_next(hContact); - } } void InitExtraIcons(void) diff --git a/protocols/AimOscar/src/utility.cpp b/protocols/AimOscar/src/utility.cpp index cabadfffb0..4fbc7a03c5 100644 --- a/protocols/AimOscar/src/utility.cpp +++ b/protocols/AimOscar/src/utility.cpp @@ -168,69 +168,50 @@ bool CAimProto::is_my_contact(HANDLE hContact) HANDLE CAimProto::find_chat_contact(const char* room) { - HANDLE hContact = db_find_first(); - while (hContact) - { - if (is_my_contact(hContact)) - { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + if (is_my_contact(hContact)) { DBVARIANT dbv; - if (!getString(hContact, "ChatRoomID", &dbv)) - { + if (!getString(hContact, "ChatRoomID", &dbv)) { bool found = !strcmp(room, dbv.pszVal); db_free(&dbv); if (found) return hContact; } } - hContact = db_find_next(hContact); } return NULL; } HANDLE CAimProto::contact_from_sn(const char* sn, bool addIfNeeded, bool temporary) { - char* norm_sn = normalize_name(sn); + mir_ptr norm_sn( normalize_name(sn)); - HANDLE hContact = db_find_first(); - while (hContact) - { - if (is_my_contact(hContact)) - { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + if (is_my_contact(hContact)) { DBVARIANT dbv; - if (!getString(hContact, AIM_KEY_SN, &dbv)) - { + if (!getString(hContact, AIM_KEY_SN, &dbv)) { bool found = !strcmp(norm_sn, dbv.pszVal); db_free(&dbv); if (found) - { - mir_free(norm_sn); return hContact; - } } } - hContact = db_find_next(hContact); } - if (addIfNeeded) - { - hContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0); - if (hContact) - { - if (CallService(MS_PROTO_ADDTOCONTACT, (WPARAM) hContact, (LPARAM) m_szModuleName) == 0) - { + if (addIfNeeded) { + HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0); + if (hContact) { + if (CallService(MS_PROTO_ADDTOCONTACT, (WPARAM) hContact, (LPARAM) m_szModuleName) == 0) { setString(hContact, AIM_KEY_SN, norm_sn); setString(hContact, AIM_KEY_NK, sn); LOG("Adding contact %s to client side list.",norm_sn); if (temporary) db_set_b(hContact, "CList", "NotOnList", 1); - mir_free(norm_sn); return hContact; } - else - CallService(MS_DB_CONTACT_DELETE, (WPARAM) hContact, 0); + CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0); } } - mir_free(norm_sn); return NULL; } @@ -340,13 +321,10 @@ void CAimProto::offline_contact(HANDLE hContact, bool remove_settings) void CAimProto::offline_contacts(void) { - HANDLE hContact = db_find_first(); - while (hContact) - { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) if (is_my_contact(hContact)) offline_contact(hContact,true); - hContact = db_find_next(hContact); - } + allow_list.destroy(); block_list.destroy(); group_list.destroy(); @@ -409,20 +387,15 @@ unsigned short CAimProto::search_for_free_item_id(HANDLE hbuddy)//returns a free retry: id = get_random(); - HANDLE hContact = db_find_first(); - while (hContact) - { - if (is_my_contact(hContact)) - { - for(int i=1; ;++i) - { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + if (is_my_contact(hContact)) { + for(int i=1; ;++i) { unsigned short item_id = getBuddyId(hContact, i); if (item_id == 0) break; if (item_id == id) goto retry; //found one no need to look through anymore } } - hContact = db_find_next(hContact); } setBuddyId(hbuddy, 1, id); @@ -435,44 +408,34 @@ unsigned short* CAimProto::get_members_of_group(unsigned short group_id, unsigne unsigned short* list = NULL; size = 0; - HANDLE hContact = db_find_first(); - while (hContact) - { - if (is_my_contact(hContact)) - { - for(int i=1; ;++i) - { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + if (is_my_contact(hContact)) { + for(int i=1; ;++i) { unsigned short user_group_id = getGroupId(hContact, i); - if (user_group_id == 0) break; + if (user_group_id == 0) + break; - if (group_id == user_group_id) - { + if (group_id == user_group_id) { unsigned short buddy_id = getBuddyId(hContact, i); - if (buddy_id) - { + if (buddy_id) { list = (unsigned short*)mir_realloc(list, ++size*sizeof(list[0])); list[size-1] = _htons(buddy_id); } } } } - hContact = db_find_next(hContact); } return list; } void CAimProto::upload_nicks(void) { - HANDLE hContact = db_find_first(); - while (hContact) - { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { DBVARIANT dbv; - if (is_my_contact(hContact) && !db_get_utf(hContact, MOD_KEY_CL, "MyHandle", &dbv)) - { + if (is_my_contact(hContact) && !db_get_utf(hContact, MOD_KEY_CL, "MyHandle", &dbv)) { set_local_nick(hContact, dbv.pszVal, NULL); db_free(&dbv); } - hContact = db_find_next(hContact); } } -- cgit v1.2.3