void WriteSetting(MCONTACT hContact, char* module1, char* setting1, char* module2, char* setting2) { CMStringA newString; char text[MAX_STRING_LENGTH]; int error = 0, status = GetLCStatus(0, 0); if (db_get_static(hContact, module1, setting1, text, _countof(text))) { switch (stringReplacer(text, newString, hContact)) { case ERROR_NO_LINE_AFTER_VAR_F: newString.Format(Translate("%s - ERROR: no line specified or line not found (in %s)"), text, setting1); error = 1; break; case ERROR_LINE_NOT_READ: newString.Format(Translate("%s - ERROR: file couldn't be opened (in %s)"), text, setting1); error = 1; break; case ERROR_NO_FILE: newString.Format(Translate("%s - ERROR: no file specified in settings (in %s)"), text, setting1); error = 1; break; default: error = 0; break; } // strip the tab and new lines from all except the tooltip if (!error && mir_strcmp(setting1, "ToolTip")) newString.TrimRight(); db_set_s(hContact, module2, setting2, newString); } else db_set_s(hContact, module2, setting2, ""); if (!error) { if ((status == ID_STATUS_ONLINE) || (status == ID_STATUS_AWAY) || (status == db_get_w(hContact, MODNAME, "Icon", ID_STATUS_ONLINE)) || db_get_b(hContact, MODNAME, "AlwaysVisible", 0)) db_set_w(hContact, MODNAME, "Status", (WORD)db_get_w(hContact, MODNAME, "Icon", ID_STATUS_ONLINE)); else db_set_w(hContact, MODNAME, "Status", ID_STATUS_OFFLINE); } else db_set_w(hContact, MODNAME, "Status", ID_STATUS_OFFLINE); }
INT_PTR CALLBACK DlgProcOtherStuff(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwnd); { MCONTACT hContact = (MCONTACT)((PROPSHEETPAGE*)lParam)->lParam; SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)hContact); if (!hContact) break; /* link*/ DBVARIANT dbv; if (!db_get_ts(hContact, MODNAME, "ProgramString", &dbv)) { SetDlgItemText(hwnd, IDC_LINK, dbv.ptszVal); db_free(&dbv); } if (!db_get_ts(hContact, MODNAME, "ProgramParamsString", &dbv)) { SetDlgItemText(hwnd, IDC_PARAMS, dbv.ptszVal); db_free(&dbv); } /* group*/ TCHAR *szGroup; for (int i = 1; (szGroup = pcli->pfnGetGroupName(i, NULL)) != NULL; i++) SendDlgItemMessage(hwnd, IDC_GROUP, CB_INSERTSTRING, 0, LPARAM(szGroup)); if (!db_get_ts(hContact, "CList", "Group", &dbv)) { SetDlgItemText(hwnd, IDC_GROUP, dbv.ptszVal); db_free(&dbv); } /* icons */ CheckRadioButton(hwnd, 40072, 40080, db_get_w(hContact, MODNAME, "Icon", ID_STATUS_ONLINE)); SetWindowLongPtr(GetDlgItem(hwnd, CHK_ONLINE), GWLP_USERDATA, (LONG_PTR)Skin_LoadProtoIcon(MODNAME, ID_STATUS_ONLINE)); g_PrevBtnWndProc = (WNDPROC)SetWindowLongPtr(GetDlgItem(hwnd, CHK_ONLINE), GWLP_WNDPROC, (LONG_PTR)ButtWndProc); for (int i = ID_STATUS_ONLINE; i <= ID_STATUS_OUTTOLUNCH; i++) { SetWindowLongPtr(GetDlgItem(hwnd, i), GWLP_USERDATA, (LONG_PTR)Skin_LoadProtoIcon(MODNAME, i)); SetWindowLongPtr(GetDlgItem(hwnd, i), GWLP_WNDPROC, (LONG_PTR)ButtWndProc); } db_free(&dbv); /* timer */ CheckDlgButton(hwnd, CHK_USE_TIMER, db_get_b(hContact, MODNAME, "UseTimer", 0) ? BST_CHECKED : BST_UNCHECKED); if (db_get_w(hContact, MODNAME, "Timer", 15)) { CheckDlgButton(hwnd, CHK_USE_TIMER, BST_CHECKED); EnableWindow(GetDlgItem(hwnd, IDC_TIMER), 1); TCHAR string[512]; SetDlgItemText(hwnd, IDC_TIMER, _itot(db_get_w(hContact, MODNAME, "Timer", 15), string, 10)); if (!db_get_w(NULL, MODNAME, "Timer", 1)) SetDlgItemText(hwnd, IDC_TIMER_INTERVAL_MSG, TranslateT("Non-IM Contact protocol timer is Disabled")); else { mir_sntprintf(string, TranslateT("Timer intervals... Non-IM Contact Protocol timer is %d seconds"), db_get_w(NULL, MODNAME, "Timer", 1)); SetDlgItemText(hwnd, IDC_TIMER_INTERVAL_MSG, string); } } /* always visible */ if (db_get_b(hContact, MODNAME, "AlwaysVisible", 0)) { CheckDlgButton(hwnd, IDC_ALWAYS_VISIBLE, BST_CHECKED); EnableWindow(GetDlgItem(hwnd, IDC_VISIBLE_UNLESS_OFFLINE), 1); CheckDlgButton(hwnd, IDC_VISIBLE_UNLESS_OFFLINE, db_get_b(hContact, MODNAME, "VisibleUnlessOffline", 1) ? BST_CHECKED : BST_UNCHECKED); } } return TRUE; case WM_COMMAND: SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0); switch (LOWORD(wParam)) { case IDC_ALWAYS_VISIBLE: if (IsDlgButtonChecked(hwnd, IDC_ALWAYS_VISIBLE)) { MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA); EnableWindow(GetDlgItem(hwnd, IDC_VISIBLE_UNLESS_OFFLINE), 1); CheckDlgButton(hwnd, IDC_VISIBLE_UNLESS_OFFLINE, db_get_b(hContact, MODNAME, "VisibleUnlessOffline", 1) ? BST_CHECKED : BST_UNCHECKED); } else EnableWindow(GetDlgItem(hwnd, IDC_VISIBLE_UNLESS_OFFLINE), 0); break; case CHK_USE_TIMER: if (IsDlgButtonChecked(hwnd, CHK_USE_TIMER)) { MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA); char string[4]; EnableWindow(GetDlgItem(hwnd, IDC_TIMER), 1); SetDlgItemTextA(hwnd, IDC_TIMER, _itoa(db_get_w(hContact, MODNAME, "Timer", 15), string, 10)); } else EnableWindow(GetDlgItem(hwnd, IDC_TIMER), 0); break; case IDC_OPEN_FILE: char szFileName[512]; if (Openfile(szFileName, 1)) SetDlgItemTextA(hwnd, IDC_LINK, szFileName); break; case IDC_OPEN_FOLDER: if (BrowseForFolder(hwnd, szFileName)) { mir_snprintf(szFileName, "%s ,/e", szFileName); SetDlgItemTextA(hwnd, IDC_LINK, "explorer.exe"); SetDlgItemTextA(hwnd, IDC_PARAMS, szFileName); } } break; case WM_NOTIFY: switch (((LPNMHDR)lParam)->idFrom) { case 0: switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: int status = GetLCStatus(0, 0); MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (GetWindowTextLength(GetDlgItem(hwnd, IDC_LINK))) { char text[512]; GetDlgItemTextA(hwnd, IDC_LINK, text, _countof(text)); db_set_s(hContact, MODNAME, "ProgramString", text); WriteSetting(hContact, MODNAME, "ProgramString", MODNAME, "Program"); } else db_unset(hContact, MODNAME, "ProgramString"); if (GetWindowTextLength(GetDlgItem(hwnd, IDC_PARAMS))) { char text[512]; GetDlgItemTextA(hwnd, IDC_PARAMS, text, _countof(text)); db_set_s(hContact, MODNAME, "ProgramParamsString", text); WriteSetting(hContact, MODNAME, "ProgramParamsString", MODNAME, "ProgramParams"); } else db_unset(hContact, MODNAME, "ProgramParamsString"); if (GetWindowTextLength(GetDlgItem(hwnd, IDC_GROUP))) { TCHAR text[512]; GetDlgItemText(hwnd, IDC_GROUP, text, _countof(text)); Clist_CreateGroup(NULL, text); db_set_ts(hContact, "CList", "Group", text); } else db_unset(hContact, "CList", "Group"); for (int i = ID_STATUS_ONLINE; i <= ID_STATUS_OUTTOLUNCH; i++) if (IsDlgButtonChecked(hwnd, i)) db_set_w(hContact, MODNAME, "Icon", (WORD)i); /* set correct status */ if (status == ID_STATUS_ONLINE || status == ID_STATUS_AWAY || (status == db_get_w(hContact, MODNAME, "Icon", ID_STATUS_ONLINE))) db_set_w(hContact, MODNAME, "Status", (WORD)db_get_w(hContact, MODNAME, "Icon", ID_STATUS_ONLINE)); else db_set_w(hContact, MODNAME, "Status", ID_STATUS_OFFLINE); if (IsDlgButtonChecked(hwnd, CHK_USE_TIMER)) { if (GetWindowTextLength(GetDlgItem(hwnd, IDC_TIMER))) { TCHAR text[512]; GetDlgItemText(hwnd, IDC_TIMER, text, _countof(text)); db_set_w(hContact, MODNAME, "Timer", (WORD)_ttoi(text)); } else db_set_w(hContact, MODNAME, "Timer", 15); } else db_set_w(hContact, MODNAME, "Timer", 0); // always visible db_set_b(hContact, MODNAME, "AlwaysVisible", (BYTE)IsDlgButtonChecked(hwnd, IDC_ALWAYS_VISIBLE)); db_set_b(hContact, MODNAME, "VisibleUnlessOffline", (BYTE)IsDlgButtonChecked(hwnd, IDC_VISIBLE_UNLESS_OFFLINE)); } return TRUE; } break; } return FALSE; }