diff options
author | George Hazan <ghazan@miranda.im> | 2017-12-09 22:07:43 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-12-09 22:07:43 +0300 |
commit | 15d04b366b37563254f914a41db97646730514b9 (patch) | |
tree | 2536d46b4c4a92338943002ffcd9e29995859748 /plugins/StopSpamPlus/src/options.cpp | |
parent | d0d6aef247ab3baf68c4ad4b2689283c1b36b0f4 (diff) |
fixes #1059 (StopSpam: account selection do not accessible for screen readers)
Diffstat (limited to 'plugins/StopSpamPlus/src/options.cpp')
-rw-r--r-- | plugins/StopSpamPlus/src/options.cpp | 283 |
1 files changed, 183 insertions, 100 deletions
diff --git a/plugins/StopSpamPlus/src/options.cpp b/plugins/StopSpamPlus/src/options.cpp index af9f587e4c..78ba677301 100644 --- a/plugins/StopSpamPlus/src/options.cpp +++ b/plugins/StopSpamPlus/src/options.cpp @@ -2,113 +2,196 @@ const wchar_t pluginDescription[] = LPGENW("No more spam! Robots can't go! Only human beings invited!\r\n\r\nThis plugin works pretty simple:\r\nWhile messages from users on your contact list go as there is no any anti-spam software, messages from unknown users are not delivered to you. But also they are not ignored, this plugin replies with a simple question, and if user gives the right answer, plugin adds him to your contact list so that he can contact you.");
-char const *answeredSetting = "Answered";
-char const *questCountSetting = "QuestionCount";
+class COptMainDlg : public CDlgBase
+{
+ CCtrlEdit edtCount;
+ CCtrlCheck chk1, chk2, chk3, chk4, chk5, chk6;
+
+public:
+ COptMainDlg() :
+ CDlgBase(hInst, IDD_MAIN),
+ edtCount(this, ID_MAXQUESTCOUNT),
+ chk1(this, ID_INFTALKPROT),
+ chk2(this, ID_ADDPERMANENT),
+ chk3(this, ID_HANDLEAUTHREQ),
+ chk4(this, ID_NOTCASESENS),
+ chk5(this, ID_REMOVE_TMP_ALL),
+ chk6(this, ID_HISTORY_LOG)
+ {}
+
+ virtual void OnInitDialog() override
+ {
+ SetDlgItemText(m_hwnd, ID_DESCRIPTION, TranslateW(pluginDescription));
-INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+ edtCount.SetInt(plSets->MaxQuestCount.Get());
+ chk1.SetState(plSets->InfTalkProtection.Get());
+ chk2.SetState(plSets->AddPermanent.Get());
+ chk3.SetState(plSets->HandleAuthReq.Get());
+ chk4.SetState(plSets->AnswNotCaseSens.Get());
+ chk5.SetState(plSets->RemTmpAll.Get());
+ chk6.SetState(plSets->HistLog.Get());
+ }
+
+ virtual void OnApply() override
+ {
+ plSets->MaxQuestCount = edtCount.GetInt();
+ plSets->InfTalkProtection = chk1.GetState();
+ plSets->AddPermanent = chk2.GetState();
+ plSets->HandleAuthReq = chk3.GetState();
+ plSets->AnswNotCaseSens = chk4.GetState();
+ plSets->RemTmpAll = chk5.GetState();
+ plSets->HistLog = chk6.GetState();
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+class COptMessageDlg : public CDlgBase
{
- switch (msg) {
- case WM_INITDIALOG:
- SetDlgItemText(hwnd, ID_DESCRIPTION, TranslateW(pluginDescription));
- TranslateDialogDefault(hwnd);
- SetDlgItemInt(hwnd, ID_MAXQUESTCOUNT, plSets->MaxQuestCount.Get(), FALSE);
- CheckDlgButton(hwnd, ID_INFTALKPROT, plSets->InfTalkProtection.Get() ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwnd, ID_ADDPERMANENT, plSets->AddPermanent.Get() ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwnd, ID_HANDLEAUTHREQ, plSets->HandleAuthReq.Get() ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwnd, ID_NOTCASESENS, plSets->AnswNotCaseSens.Get() ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwnd, ID_REMOVE_TMP_ALL, plSets->RemTmpAll.Get() ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwnd, ID_HISTORY_LOG, plSets->HistLog.Get() ? BST_CHECKED : BST_UNCHECKED);
- return TRUE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case ID_MAXQUESTCOUNT:
- if (EN_CHANGE != HIWORD(wParam) || (HWND)lParam != GetFocus())
- return FALSE;
- break;
-
- case ID_DESCRIPTION:
- return FALSE;
- }
- SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
- break;
-
- case WM_NOTIFY:
- NMHDR* nmhdr = (NMHDR*)lParam;
- switch (nmhdr->code) {
- case PSN_APPLY:
- plSets->MaxQuestCount = GetDlgItemInt(hwnd, ID_MAXQUESTCOUNT, nullptr, FALSE);
- plSets->InfTalkProtection = (BST_CHECKED == IsDlgButtonChecked(hwnd, ID_INFTALKPROT));
- plSets->AddPermanent = (BST_CHECKED == IsDlgButtonChecked(hwnd, ID_ADDPERMANENT));
- plSets->HandleAuthReq = (BST_CHECKED == IsDlgButtonChecked(hwnd, ID_HANDLEAUTHREQ));
- plSets->AnswNotCaseSens = (BST_CHECKED == IsDlgButtonChecked(hwnd, ID_NOTCASESENS));
- plSets->RemTmpAll = (BST_CHECKED == IsDlgButtonChecked(hwnd, ID_REMOVE_TMP_ALL));
- plSets->HistLog = (BST_CHECKED == IsDlgButtonChecked(hwnd, ID_HISTORY_LOG));
- return TRUE;
- }
- break;
+ CCtrlButton btnHelp, btnRestore;
+ CCtrlEdit edtQuestion, edtAnswer, edtCongrat, edtReply, edtDivider;
+
+public:
+ COptMessageDlg() :
+ CDlgBase(hInst, IDD_MESSAGES),
+ btnHelp(this, IDC_VARS),
+ btnRestore(this, ID_RESTOREDEFAULTS),
+ edtQuestion(this, ID_QUESTION),
+ edtAnswer(this, ID_ANSWER),
+ edtCongrat(this, ID_CONGRATULATION),
+ edtReply(this, ID_AUTHREPL),
+ edtDivider(this, ID_DIVIDER)
+ {
+ btnHelp.OnClick = Callback(this, &COptMessageDlg::onHelp);
+ btnRestore.OnClick = Callback(this, &COptMessageDlg::onRestore);
}
- return FALSE;
-}
-INT_PTR CALLBACK MessagesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+ virtual void OnInitDialog() override
+ {
+ edtQuestion.SetText(plSets->Question.Get().c_str());
+ edtAnswer.SetText(plSets->Answer.Get().c_str());
+ edtCongrat.SetText(plSets->Congratulation.Get().c_str());
+ edtReply.SetText(plSets->AuthRepl.Get().c_str());
+ edtDivider.SetText(plSets->AnswSplitString.Get().c_str());
+ variables_skin_helpbutton(m_hwnd, IDC_VARS);
+ btnHelp.Enable(ServiceExists(MS_VARS_FORMATSTRING));
+ }
+
+ virtual void OnApply() override
+ {
+ plSets->Question = ptrW(edtQuestion.GetText()).get();
+ plSets->Answer = ptrW(edtAnswer.GetText()).get();
+ plSets->AuthRepl = ptrW(edtCongrat.GetText()).get();
+ plSets->Congratulation = ptrW(edtReply.GetText()).get();
+ plSets->AnswSplitString = ptrW(edtDivider.GetText()).get();
+ }
+
+ void onHelp(CCtrlButton*)
+ {
+ variables_showhelp(m_hwnd, WM_COMMAND, VHF_FULLDLG | VHF_SETLASTSUBJECT, nullptr, nullptr);
+ }
+
+ void onRestore(CCtrlButton*)
+ {
+ edtQuestion.SetText(plSets->Question.GetDefault().c_str());
+ edtAnswer.SetText(plSets->Answer.GetDefault().c_str());
+ edtCongrat.SetText(plSets->Congratulation.GetDefault().c_str());
+ edtReply.SetText(plSets->AuthRepl.GetDefault().c_str());
+ edtDivider.SetText(plSets->AnswSplitString.GetDefault().c_str());
+ NotifyChange();
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+class COptAccountDlg : public CDlgBase
{
+ CCtrlListView m_accounts;
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwnd);
- SetDlgItemString(hwnd, ID_QUESTION, plSets->Question.Get());
- SetDlgItemString(hwnd, ID_ANSWER, plSets->Answer.Get());
- SetDlgItemString(hwnd, ID_CONGRATULATION, plSets->Congratulation.Get());
- SetDlgItemString(hwnd, ID_AUTHREPL, plSets->AuthRepl.Get());
- SetDlgItemString(hwnd, ID_DIVIDER, plSets->AnswSplitString.Get());
- variables_skin_helpbutton(hwnd, IDC_VARS);
- ServiceExists(MS_VARS_FORMATSTRING) ? EnableWindow(GetDlgItem(hwnd, IDC_VARS), 1) : EnableWindow(GetDlgItem(hwnd, IDC_VARS), 0);
- return TRUE;
-
- case WM_COMMAND:
- {
- switch (LOWORD(wParam)) {
- case ID_QUESTION:
- case ID_ANSWER:
- case ID_AUTHREPL:
- case ID_CONGRATULATION:
- case ID_DIVIDER:
- if (EN_CHANGE != HIWORD(wParam) || (HWND)lParam != GetFocus())
- return FALSE;
- break;
-
- case ID_RESTOREDEFAULTS:
- SetDlgItemString(hwnd, ID_QUESTION, plSets->Question.GetDefault());
- SetDlgItemString(hwnd, ID_ANSWER, plSets->Answer.GetDefault());
- SetDlgItemString(hwnd, ID_CONGRATULATION, plSets->Congratulation.GetDefault());
- SetDlgItemString(hwnd, ID_AUTHREPL, plSets->AuthRepl.GetDefault());
- SetDlgItemString(hwnd, ID_DIVIDER, plSets->AnswSplitString.GetDefault());
- SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
- return TRUE;
-
- case IDC_VARS:
- variables_showhelp(hwnd, msg, VHF_FULLDLG | VHF_SETLASTSUBJECT, nullptr, nullptr);
- return TRUE;
- }
- SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
+public:
+ COptAccountDlg() :
+ CDlgBase(hInst, IDD_PROTO),
+ m_accounts(this, IDC_PROTO)
+ {
+ m_accounts.OnItemChanged = Callback(this, &COptAccountDlg::list_OnItemChanged);
+ }
+
+ virtual void OnInitDialog() override
+ {
+ m_accounts.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES);
+ m_accounts.DeleteAllItems();
+
+ LVCOLUMN lvc = {};
+ lvc.mask = LVCF_WIDTH;
+ lvc.fmt = LVCFMT_IMAGE | LVCFMT_LEFT;
+ lvc.cx = 250;
+ m_accounts.InsertColumn(0, &lvc);
+
+ LVITEM item = { 0 };
+ item.mask = LVIF_TEXT | LVIF_PARAM;
+ item.iItem = 1000;
+
+ int n;
+ PROTOACCOUNT **pa;
+ Proto_EnumAccounts(&n, &pa);
+
+ for (int i = 0; i < n; i++) {
+ PROTOACCOUNT *p = pa[i];
+ if (!Proto_IsAccountEnabled(p) || p->bIsVirtual)
+ continue;
+
+ item.lParam = (LPARAM)p->szModuleName;
+ item.pszText = p->tszAccountName;
+ int idx = m_accounts.InsertItem(&item);
+ m_accounts.SetCheckState(idx, !plSets->ProtoDisabled(p->szModuleName));
}
- break;
-
- case WM_NOTIFY:
- NMHDR* nmhdr = (NMHDR*)lParam;
- switch (nmhdr->code) {
- case PSN_APPLY:
- {
- plSets->Question = GetDlgItemString(hwnd, ID_QUESTION);
- plSets->Answer = GetDlgItemString(hwnd, ID_ANSWER);
- plSets->AuthRepl = GetDlgItemString(hwnd, ID_AUTHREPL);
- plSets->Congratulation = GetDlgItemString(hwnd, ID_CONGRATULATION);
- plSets->AnswSplitString = GetDlgItemString(hwnd, ID_DIVIDER);
- }
- return TRUE;
+ }
+
+ virtual void OnApply() override
+ {
+ std::ostringstream out;
+
+ LVITEM item;
+ item.mask = LVIF_PARAM;
+
+ for (int i = 0; i < m_accounts.GetItemCount(); i++) {
+ item.iItem = i;
+ if (!m_accounts.GetItem(&item))
+ continue;
+
+ if (m_accounts.GetCheckState(i) != 0)
+ out << (char*)item.lParam << " ";
}
- break;
+
+ plSets->DisabledProtoList = out.str();
}
- return FALSE;
+
+ void list_OnItemChanged(CCtrlListView::TEventInfo*)
+ {
+ if (m_initialized)
+ NotifyChange();
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// options initializer
+
+int OnOptInit(WPARAM w, LPARAM)
+{
+ OPTIONSDIALOGPAGE odp = { 0 };
+ odp.szGroup.a = LPGEN("Message sessions");
+ odp.szTitle.a = pluginName;
+
+ odp.szTab.a = LPGEN("General");
+ odp.pDialog = new COptMainDlg();
+ Options_AddPage(w, &odp);
+
+ odp.szTab.a = LPGEN("Messages");
+ odp.pDialog = new COptMessageDlg();
+ Options_AddPage(w, &odp);
+
+ odp.szTab.a = LPGEN("Accounts");
+ odp.pDialog = new COptAccountDlg();
+ Options_AddPage(w, &odp);
+ return 0;
}
|