From a5e65f02c7e37bed18fbca915e8040358d0f4fe7 Mon Sep 17 00:00:00 2001 From: Tobias Weimer Date: Wed, 7 Oct 2015 18:59:19 +0000 Subject: Non-IM Contact: - Minor code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@15516 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Non-IM Contact/src/contactinfo.cpp | 51 ++++++++++++++++-------------- 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'plugins/Non-IM Contact/src/contactinfo.cpp') diff --git a/plugins/Non-IM Contact/src/contactinfo.cpp b/plugins/Non-IM Contact/src/contactinfo.cpp index 855d2eef6f..1c028354a3 100644 --- a/plugins/Non-IM Contact/src/contactinfo.cpp +++ b/plugins/Non-IM Contact/src/contactinfo.cpp @@ -10,9 +10,11 @@ INT_PTR CALLBACK DlgProcContactInfo(HWND hwnd, UINT msg, WPARAM, LPARAM lParam) char name[2048]; SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)hContact); - if (!db_get_static(hContact, MODNAME, "Name", name, _countof(name))) break; + if (db_get_static(hContact, MODNAME, "Name", name, _countof(name))) + break; SetDlgItemTextA(hwnd, IDC_DISPLAY_NAME, name); - if (!db_get_static(hContact, MODNAME, "ToolTip", name, _countof(name))) break; + if (db_get_static(hContact, MODNAME, "ToolTip", name, _countof(name))) + break; SetDlgItemTextA(hwnd, IDC_TOOLTIP, name); } return TRUE; @@ -310,8 +312,8 @@ INT_PTR CALLBACK DlgProcCopy(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) char dbVar1[2000], dbVar2[2000]; int i = 0, j = 0, k = 0; char *string = oldString[k]; - MCONTACT hContact1 = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA), hContact2; - if (db_get_static(hContact1, MODNAME, "Name", dbVar1, _countof(dbVar1))) { + MCONTACT hContact1 = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA); + if (!db_get_static(hContact1, MODNAME, "Name", dbVar1, _countof(dbVar1))) { char *replace = (char*)malloc(GetWindowTextLength(GetDlgItem(hwnd, IDC_STRING_REPLACE)) + 1); GetDlgItemTextA(hwnd, IDC_STRING_REPLACE, replace, GetWindowTextLength(GetDlgItem(hwnd, IDC_STRING_REPLACE)) + 1); // get the list of replace strings @@ -323,7 +325,8 @@ INT_PTR CALLBACK DlgProcCopy(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) else if (!strncmp(replace + i, "\r\n", 2)) { if (string == newString[k]) k--; - if (k == MAX_REPLACES) break; + if (k == MAX_REPLACES) + break; string = oldString[++k]; i += 2; continue; @@ -335,19 +338,19 @@ INT_PTR CALLBACK DlgProcCopy(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) i++; } free(replace); - hContact2 = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); + MCONTACT hContact2 = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); Proto_AddToContact(hContact2, MODNAME); CallService(MS_IGNORE_IGNORE, (WPARAM)hContact2, IGNOREEVENT_USERONLINE); db_set_s(hContact2, MODNAME, "Nick", Translate("New Non-IM Contact")); // blank dbVar2 so the replaceing doesnt crash.. mir_strcpy(dbVar2, ""); // copy the name (dbVar1 is the name) - for (i = 0; i <= k; i++) + for (i = 0; i < k; i++) copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]); db_set_s(hContact2, MODNAME, "Name", dbVar2); // copy the ProgramString - if (db_get_static(hContact1, MODNAME, "ProgramString", dbVar1, _countof(dbVar1))) { + if (!db_get_static(hContact1, MODNAME, "ProgramString", dbVar1, _countof(dbVar1))) { mir_strcpy(dbVar2, ""); for (i = 0; i <= k; i++) copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]); @@ -355,7 +358,7 @@ INT_PTR CALLBACK DlgProcCopy(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) db_set_s(hContact2, MODNAME, "ProgramString", dbVar2); } // copy the ProgramParamString - if (db_get_static(hContact1, MODNAME, "ProgramParamString", dbVar1, _countof(dbVar1))) { + if (!db_get_static(hContact1, MODNAME, "ProgramParamString", dbVar1, _countof(dbVar1))) { mir_strcpy(dbVar2, ""); for (i = 0; i <= k; i++) copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]); @@ -363,7 +366,7 @@ INT_PTR CALLBACK DlgProcCopy(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) db_set_s(hContact2, MODNAME, "ProgramParamString", dbVar2); } // copy the group - if (db_get_static(hContact1, "CList", "Group", dbVar1, _countof(dbVar1))) { + if (!db_get_static(hContact1, "CList", "Group", dbVar1, _countof(dbVar1))) { mir_strcpy(dbVar2, ""); for (i = 0; i <= k; i++) copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]); @@ -371,7 +374,7 @@ INT_PTR CALLBACK DlgProcCopy(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) db_set_s(hContact2, "CList", "Group", dbVar2); } // copy the ToolTip - if (db_get_static(hContact1, MODNAME, "ToolTip", dbVar1, _countof(dbVar1))) { + if (!db_get_static(hContact1, MODNAME, "ToolTip", dbVar1, _countof(dbVar1))) { mir_strcpy(dbVar2, ""); for (i = 0; i <= k; i++) copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]); @@ -390,7 +393,7 @@ INT_PTR CALLBACK DlgProcCopy(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) else { char dbVar1[2000]; MCONTACT hContact1 = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if (db_get_static(hContact1, MODNAME, "Name", dbVar1, _countof(dbVar1))) { + if (!db_get_static(hContact1, MODNAME, "Name", dbVar1, _countof(dbVar1))) { MCONTACT hContact2 = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); if (!hContact2) { msg("contact did not get created", ""); @@ -400,19 +403,19 @@ INT_PTR CALLBACK DlgProcCopy(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) CallService(MS_IGNORE_IGNORE, (WPARAM)hContact2, IGNOREEVENT_USERONLINE); db_set_s(hContact2, MODNAME, "Nick", Translate("New Non-IM Contact")); db_set_s(hContact2, MODNAME, "Name", dbVar1); - if (db_get_static(hContact1, MODNAME, "ProgramString", dbVar1, _countof(dbVar1))) + if (!db_get_static(hContact1, MODNAME, "ProgramString", dbVar1, _countof(dbVar1))) db_set_s(hContact2, MODNAME, "ProgramString", dbVar1); // copy the ProgramParamString - if (db_get_static(hContact1, MODNAME, "ProgramParamString", dbVar1, _countof(dbVar1))) + if (!db_get_static(hContact1, MODNAME, "ProgramParamString", dbVar1, _countof(dbVar1))) db_set_s(hContact2, MODNAME, "ProgramParamString", dbVar1); // copy the group - if (db_get_static(hContact1, "CList", "Group", dbVar1, _countof(dbVar1))) + if (!db_get_static(hContact1, "CList", "Group", dbVar1, _countof(dbVar1))) db_set_s(hContact2, "CList", "Group", dbVar1); // copy the ToolTip - if (db_get_static(hContact1, MODNAME, "ToolTip", dbVar1, _countof(dbVar1))) + if (!db_get_static(hContact1, MODNAME, "ToolTip", dbVar1, _countof(dbVar1))) db_set_s(hContact2, MODNAME, "ToolTip", dbVar1); // timer @@ -453,15 +456,15 @@ void ExportContact(MCONTACT hContact) // else FILE *file = fopen(szFileName, "a"); if (file) { - if (db_get_static(hContact, MODNAME, "Name", DBVar, _countof(DBVar))) { + if (!db_get_static(hContact, MODNAME, "Name", DBVar, _countof(DBVar))) { fprintf(file, "\r\n[Non-IM Contact]\r\nName=%s\r\n", DBVar); - if (db_get_static(hContact, MODNAME, "ProgramString", DBVar, _countof(DBVar))) + if (!db_get_static(hContact, MODNAME, "ProgramString", DBVar, _countof(DBVar))) fprintf(file, "ProgramString=%s\r\n", DBVar); - if (db_get_static(hContact, MODNAME, "ProgramParamString", DBVar, _countof(DBVar))) + if (!db_get_static(hContact, MODNAME, "ProgramParamString", DBVar, _countof(DBVar))) fprintf(file, "ProgramParamString=%s\r\n", DBVar); - if (db_get_static(hContact, MODNAME, "ToolTip", DBVar, _countof(DBVar))) + if (!db_get_static(hContact, MODNAME, "ToolTip", DBVar, _countof(DBVar))) fprintf(file, "ToolTip=%s\r\n", DBVar); - if (db_get_static(hContact, "CList", "Group", DBVar, _countof(DBVar))) + if (!db_get_static(hContact, "CList", "Group", DBVar, _countof(DBVar))) fprintf(file, "Group=%s\r\n", DBVar); if (tmp = db_get_w(hContact, MODNAME, "Icon", 40072)) fprintf(file, "Icon=%d\r\n", tmp); @@ -561,13 +564,13 @@ INT_PTR ImportContacts(WPARAM, LPARAM) size_t size = mir_strlen(name) + mir_strlen("Do you want to import this Non-IM Contact?\r\n\r\nName: \r\n") + 1; char *msg = (char*)malloc(size); mir_snprintf(msg, size, "Do you want to import this Non-IM Contact?\r\n\r\nName: %s\r\n", name); - if (program) { + if (program[0] != '\0') { msg = (char*)realloc(msg, mir_strlen(msg) + mir_strlen(program) + mir_strlen("Program: \r\n") + 1); mir_strcat(msg, "Program: "); mir_strcat(msg, program); mir_strcat(msg, "\r\n"); } - if (programparam) { + if (programparam[0] != '\0') { msg = (char*)realloc(msg, mir_strlen(msg) + mir_strlen(programparam) + mir_strlen("Program Parameters: \r\n") + 1); mir_strcat(msg, "Program Parameters: "); mir_strcat(msg, programparam); @@ -579,7 +582,7 @@ INT_PTR ImportContacts(WPARAM, LPARAM) mir_strcat(msg, tooltip); mir_strcat(msg, "\r\n"); } - if (group) { + if (group[0] != '\0') { msg = (char*)realloc(msg, mir_strlen(msg) + mir_strlen(group) + mir_strlen("Group: \r\n") + 1); mir_strcat(msg, "Group: "); mir_strcat(msg, group); -- cgit v1.2.3