From 0b084cff5bb71a140d5181caa452a95b74ac8103 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 8 Dec 2018 18:35:02 +0300 Subject: chats: - Chat_GetGroup & Chat_SetGroup functions added to stop the zoo with chat default group name; - fixes #1655 (custom chat group name doesn't work in Discord) --- plugins/Scriver/src/chat_options.cpp | 25 +++++-------------------- plugins/TabSRMM/src/chat_options.cpp | 14 ++++---------- 2 files changed, 9 insertions(+), 30 deletions(-) (limited to 'plugins') diff --git a/plugins/Scriver/src/chat_options.cpp b/plugins/Scriver/src/chat_options.cpp index d128a7d832..fdf53a98f9 100644 --- a/plugins/Scriver/src/chat_options.cpp +++ b/plugins/Scriver/src/chat_options.cpp @@ -221,16 +221,6 @@ static INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM p return 0; } -static void InitSetting(wchar_t **ppPointer, char *pszSetting, wchar_t *pszDefault) -{ - DBVARIANT dbv; - if (!db_get_ws(0, CHAT_MODULE, pszSetting, &dbv)) { - replaceStrW(*ppPointer, dbv.pwszVal); - db_free(&dbv); - } - else replaceStrW(*ppPointer, pszDefault); -} - #define OPT_FIXHEADINGS (WM_USER+1) INT_PTR CALLBACK DlgProcOptions1(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) @@ -248,12 +238,7 @@ INT_PTR CALLBACK DlgProcOptions1(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM FillBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading1, branch1, _countof(branch1), 0); FillBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading4, branch4, _countof(branch4), 0x1000); SendMessage(hwndDlg, OPT_FIXHEADINGS, 0, 0); - { - wchar_t* pszGroup = nullptr; - InitSetting(&pszGroup, "AddToGroup", L"Chat rooms"); - SetDlgItemText(hwndDlg, IDC_CHAT_GROUP, pszGroup); - mir_free(pszGroup); - } + SetDlgItemText(hwndDlg, IDC_CHAT_GROUP, ptrW(Chat_GetGroup())); break; case OPT_FIXHEADINGS: @@ -316,11 +301,11 @@ INT_PTR CALLBACK DlgProcOptions1(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM case PSN_APPLY: int iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_CHAT_GROUP)); if (iLen > 0) { - ptrA pszText((char*)mir_alloc(iLen + 1)); - GetDlgItemTextA(hwndDlg, IDC_CHAT_GROUP, pszText, iLen + 1); - db_set_s(0, CHAT_MODULE, "AddToGroup", pszText); + ptrW pszText((wchar_t*)mir_alloc(sizeof(wchar_t)*(iLen + 1))); + GetDlgItemTextW(hwndDlg, IDC_CHAT_GROUP, pszText, iLen + 1); + Chat_SetGroup(pszText); } - else db_set_s(0, CHAT_MODULE, "AddToGroup", ""); + else Chat_SetGroup(nullptr); iLen = SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN2, UDM_GETPOS, 0, 0); if (iLen > 0) diff --git a/plugins/TabSRMM/src/chat_options.cpp b/plugins/TabSRMM/src/chat_options.cpp index e6329e9ce7..3b973cc1b2 100644 --- a/plugins/TabSRMM/src/chat_options.cpp +++ b/plugins/TabSRMM/src/chat_options.cpp @@ -535,6 +535,7 @@ class CChatSettingsDlg : public CChatBaseOptionDlg HTREEITEM hListHeading2 = nullptr; CCtrlTreeView treeCheck; + CCtrlEdit edtGroup; HTREEITEM InsertBranch(wchar_t* pszDescr, BOOL bExpanded) { @@ -594,6 +595,7 @@ class CChatSettingsDlg : public CChatBaseOptionDlg public: CChatSettingsDlg() : CChatBaseOptionDlg(IDD_OPTIONS1), + edtGroup(this, IDC_GROUP), treeCheck(this, IDC_CHECKBOXES) {} @@ -610,21 +612,13 @@ public: FillBranch(hListHeading1, branch1, _countof(branch1), 0x0000); FillBranch(hListHeading2, branch2, _countof(branch2), 0x0000); - ptrW pszGroup(db_get_wsa(0, CHAT_MODULE, "AddToGroup")); - SetDlgItemText(m_hwnd, IDC_GROUP, (pszGroup != nullptr) ? pszGroup : TranslateT("Chat rooms")); + edtGroup.SetText(ptrW(Chat_GetGroup())); return true; } bool OnApply() override { - int iLen = GetWindowTextLength(GetDlgItem(m_hwnd, IDC_GROUP)); - if (iLen > 0) { - wchar_t *pszText = (wchar_t*)mir_alloc((iLen + 2) * sizeof(wchar_t)); - GetDlgItemText(m_hwnd, IDC_GROUP, pszText, iLen + 1); - db_set_ws(0, CHAT_MODULE, "AddToGroup", pszText); - mir_free(pszText); - } - else db_set_ws(0, CHAT_MODULE, "AddToGroup", L""); + Chat_SetGroup(ptrW(edtGroup.GetText())); SaveBranch(branch1, _countof(branch1)); SaveBranch(branch2, _countof(branch2)); -- cgit v1.2.3