diff options
author | George Hazan <ghazan@miranda.im> | 2021-06-15 15:29:00 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-06-15 15:29:00 +0300 |
commit | 675042de86f7fa98659a7e0aac67fbdb84bc0daa (patch) | |
tree | 6ee4f41f79f1983caa8aabf75e7be190833750db /plugins/BuddyPounce/src | |
parent | eaa5f40645f0140f39c07b899e80cbd149d4c727 (diff) |
BuddyPounce:
- fixes #2920 (BuddyPounce: не сохраняются числовые настройки Buddy pounce);
- fixes #2919 (BuddyPounce: make dialog bigger);
- options extracted to the separate module;
- all dialogs are rewritten using UI classes;
- duplicate code removed;
Diffstat (limited to 'plugins/BuddyPounce/src')
-rw-r--r-- | plugins/BuddyPounce/src/dialog.cpp | 689 | ||||
-rw-r--r-- | plugins/BuddyPounce/src/main.cpp | 101 | ||||
-rw-r--r-- | plugins/BuddyPounce/src/options.cpp | 245 | ||||
-rw-r--r-- | plugins/BuddyPounce/src/resource.h | 6 | ||||
-rw-r--r-- | plugins/BuddyPounce/src/stdafx.h | 106 | ||||
-rw-r--r-- | plugins/BuddyPounce/src/version.h | 4 |
6 files changed, 551 insertions, 600 deletions
diff --git a/plugins/BuddyPounce/src/dialog.cpp b/plugins/BuddyPounce/src/dialog.cpp index 129f8504bd..19bb83e048 100644 --- a/plugins/BuddyPounce/src/dialog.cpp +++ b/plugins/BuddyPounce/src/dialog.cpp @@ -1,176 +1,122 @@ #include "stdafx.h"
-void populateSettingsList(HWND hwnd2List)
+void getDefaultMessage(HWND hwnd, UINT control, MCONTACT hContact)
{
- SendMessage(hwnd2List, LB_ADDSTRING, 0, (LPARAM)TranslateT("Send If My Status Is..."));
- SendMessage(hwnd2List, LB_ADDSTRING, 0, (LPARAM)TranslateT("Send If They Change Status to..."));
- SendMessage(hwnd2List, LB_ADDSTRING, 0, (LPARAM)L"----------------------------");
- SendMessage(hwnd2List, LB_ADDSTRING, 0, (LPARAM)TranslateT("Reuse Pounce"));
- SendMessage(hwnd2List, LB_ADDSTRING, 0, (LPARAM)TranslateT("Give Up delay"));
- SendMessage(hwnd2List, LB_ADDSTRING, 0, (LPARAM)TranslateT("Confirmation Window"));
+ DBVARIANT dbv;
+ if (!g_plugin.getWString(hContact, "PounceMsg", &dbv)) {
+ SetDlgItemText(hwnd, control, dbv.pwszVal);
+ db_free(&dbv);
+ }
+ else if (!g_plugin.getWString("PounceMsg", &dbv)) {
+ SetDlgItemText(hwnd, control, dbv.pwszVal);
+ db_free(&dbv);
+ }
}
-void populateContacts(MCONTACT BPhContact, HWND hwnd2CB)
+/////////////////////////////////////////////////////////////////////////////////////////
+
+CBuddyPounceBasicDlg::CBuddyPounceBasicDlg(int dlgId) :
+ CDlgBase(g_plugin, dlgId),
+ edtMessage(this, IDC_MESSAGE)
{
- for (auto &hContact : Contacts()) {
- char *szProto = Proto_GetBaseAccountName(hContact);
- if (szProto && (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IM)) {
- wchar_t name[300];
- mir_snwprintf(name, L"%s (%S)", Clist_GetContactDisplayName(hContact), szProto);
- int index = SendMessage(hwnd2CB, CB_ADDSTRING, 0, (LPARAM)name);
- SendMessage(hwnd2CB, CB_SETITEMDATA, index, hContact);
- if (BPhContact == hContact)
- SendMessage(hwnd2CB, CB_SETCURSEL, index, 0);
- }
- }
+ edtMessage.OnChange = Callback(this, &CBuddyPounceBasicDlg::onChanged_Message);
}
-void saveLastSetting(MCONTACT hContact, HWND hwnd)
+bool CBuddyPounceBasicDlg::OnInitDialog()
{
- wchar_t number[8];//, string[1024];//for sending file name
- switch (g_plugin.getByte(hContact, "LastSetting", 2)) { // nothing to do
- case 0: // Send If My Status Is...
- break;
- case 1: // Send If They Change status to
- break;
- case 2: // ------, fall through
- case 6: // nothing to do...
- break;
- case 3: // Reuse Pounce
- GetDlgItemText(hwnd, IDC_SETTINGNUMBER, number, _countof(number));
- g_plugin.setByte(hContact, "Reuse", (BYTE)_wtoi(number));
- break;
- case 4: // Give Up delay
- GetDlgItemText(hwnd, IDC_SETTINGNUMBER, number, _countof(number));
- g_plugin.setByte(hContact, "GiveUpDays", (BYTE)_wtoi(number));
- {
- g_plugin.setDword(hContact, "GiveUpDate", (DWORD)(_wtoi(number)*SECONDSINADAY));
- }
- break;
- case 5: // confirm window
- GetDlgItemText(hwnd, IDC_SETTINGNUMBER, number, _countof(number));
- g_plugin.setWord(hContact, "ConfirmTimeout", (WORD)_wtoi(number));
- break;
- }
+ getDefaultMessage(m_hwnd, IDC_MESSAGE, hContact);
+ onChanged_Message(0);
+ return true;
}
-void hideAll(HWND hwnd)
+bool CBuddyPounceBasicDlg::OnApply()
{
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGMSG), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGMSG2), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGNUMBER), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, IDC_SPIN), SW_HIDE);
+ ptrW wszMessage(edtMessage.GetText());
+ if (mir_wstrlen(wszMessage))
+ g_plugin.setWString(hContact, "PounceMsg", wszMessage);
+ else
+ g_plugin.delSetting(hContact, "PounceMsg");
+ return true;
}
-void getDefaultMessage(HWND hwnd, UINT control, MCONTACT hContact)
+void CBuddyPounceBasicDlg::onChanged_Message(CCtrlEdit *)
{
- DBVARIANT dbv;
- if (!g_plugin.getWString(hContact, "PounceMsg", &dbv)) {
- SetDlgItemText(hwnd, control, dbv.pwszVal);
- db_free(&dbv);
- }
- else if (!g_plugin.getWString("PounceMsg", &dbv)) {
- SetDlgItemText(hwnd, control, dbv.pwszVal);
- db_free(&dbv);
- }
+ int length = GetWindowTextLength(edtMessage.GetHwnd());
+ CMStringW str(FORMAT, TranslateT("The Message (%d Characters)"), length);
+ SetDlgItemTextW(m_hwnd, GRP_MSG, str);
}
-INT_PTR CALLBACK StatusModesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+/////////////////////////////////////////////////////////////////////////////////////////
+// CBuddyPounceSimpleDlg class implementation
+
+CBuddyPounceSimpleDlg::CBuddyPounceSimpleDlg(MCONTACT _1) :
+ CSuper(IDD_POUNCE_SIMPLE),
+ btnAdvanced(this, IDC_ADVANCED)
{
- switch (msg) {
- case WM_INITDIALOG:
- SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam); // windowInfo*
- TranslateDialogDefault(hwnd);
-
- return FALSE;
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDOK:
- case IDCANCEL:
- windowInfo * wi = (windowInfo *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- wchar_t type[32];
- GetDlgItemText(hwnd, IDC_CHECK1, type, _countof(type));
-
- WORD flag = (IsDlgButtonChecked(hwnd, IDC_CHECK1))
- | (IsDlgButtonChecked(hwnd, IDC_CHECK2) << 1)
- | (IsDlgButtonChecked(hwnd, IDC_CHECK3) << 2)
- | (IsDlgButtonChecked(hwnd, IDC_CHECK4) << 3)
- | (IsDlgButtonChecked(hwnd, IDC_CHECK5) << 4)
- | (IsDlgButtonChecked(hwnd, IDC_CHECK6) << 5)
- | (IsDlgButtonChecked(hwnd, IDC_CHECK7) << 6)
- | (IsDlgButtonChecked(hwnd, IDC_CHECK8) << 7);
-
- if (!mir_wstrcmp(type, L"Any")) {
- if (LOWORD(wParam) == IDOK)
- g_plugin.setWord(wi->hContact, "SendIfMyStatusIsFLAG", flag);
- wi->SendIfMy = nullptr;
- }
- else {
- if (LOWORD(wParam) == IDOK)
- g_plugin.setWord(wi->hContact, "SendIfTheirStatusIsFLAG", flag);
- wi->SendWhenThey = nullptr;
- }
- DestroyWindow(hwnd);
- }
- break;
- }
- return FALSE;
+ hContact = _1;
+
+ btnAdvanced.OnClick = Callback(this, &CBuddyPounceSimpleDlg::onClick_Advanced);
}
-void statusModes(windowInfo *wi, int myStatusMode) // myStatusMode=1 sendIfMyStatusFlag
+
+void CBuddyPounceSimpleDlg::onClick_Advanced(CCtrlButton *)
{
- int statusFlag;
- HWND hwnd;
+ (new CBuddyPounceDlg(hContact))->Create();
- if (myStatusMode) {
- if (wi->SendIfMy) {
- SetForegroundWindow(wi->SendIfMy);
- return;
- }
- else {
- hwnd = wi->SendIfMy = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_STATUSMODES), nullptr, StatusModesDlgProc, (LPARAM)wi);
- statusFlag = g_plugin.getWord(wi->hContact, "SendIfMyStatusIsFLAG", 0);
- SetWindowText(hwnd, TranslateT("Send If My Status Is"));
- SetDlgItemText(hwnd, IDC_CHECK1, TranslateT("Any"));
- SetDlgItemText(hwnd, IDC_CHECK2, TranslateT("Online"));
- SetDlgItemText(hwnd, IDC_CHECK3, TranslateT("Away"));
- SetDlgItemText(hwnd, IDC_CHECK4, TranslateT("Not available"));
- SetDlgItemText(hwnd, IDC_CHECK5, TranslateT("Occupied"));
- SetDlgItemText(hwnd, IDC_CHECK6, TranslateT("Do not disturb"));
- SetDlgItemText(hwnd, IDC_CHECK7, TranslateT("Free for chat"));
- SetDlgItemText(hwnd, IDC_CHECK8, TranslateT("Invisible"));
- }
- }
- else {
- if (wi->SendWhenThey) {
- SetForegroundWindow(wi->SendWhenThey);
- return;
- }
- else {
- hwnd = wi->SendWhenThey = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_STATUSMODES), nullptr, StatusModesDlgProc, (LPARAM)wi);
- statusFlag = g_plugin.getWord(wi->hContact, "SendIfTheirStatusIsFLAG", 0);
- SetWindowText(hwnd, TranslateT("Send If Their Status changes"));
- SetDlgItemText(hwnd, IDC_CHECK1, TranslateT("From Offline"));
- SetDlgItemText(hwnd, IDC_CHECK2, TranslateT("To Online"));
- SetDlgItemText(hwnd, IDC_CHECK3, TranslateT("To Away"));
- SetDlgItemText(hwnd, IDC_CHECK4, TranslateT("To Not available"));
- SetDlgItemText(hwnd, IDC_CHECK5, TranslateT("To Occupied"));
- SetDlgItemText(hwnd, IDC_CHECK6, TranslateT("To Do not disturb"));
- SetDlgItemText(hwnd, IDC_CHECK7, TranslateT("To Free for chat"));
- SetDlgItemText(hwnd, IDC_CHECK8, TranslateT("To Invisible"));
+ OnApply();
+ Close();
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+CBuddyPounceDlg::CBuddyPounceDlg(MCONTACT _1) :
+ CSuper(IDD_POUNCE),
+ m_contacts(this, IDC_CONTACTS),
+ chkSimple(this, IDC_SIMPLE),
+ btnDelete(this, IDC_DELETE),
+ btnDefault(this, IDC_DEFAULT)
+{
+ hContact = _1;
+
+ btnDelete.OnClick = Callback(this, &CBuddyPounceDlg::onClick_Delete);
+ btnDefault.OnClick = Callback(this, &CBuddyPounceDlg::onClick_Default);
+
+ chkSimple.OnChange = Callback(this, &CBuddyPounceDlg::onChange_Simple);
+}
+
+bool CBuddyPounceDlg::OnInitDialog()
+{
+ CSuper::OnInitDialog();
+
+ // populate contacts
+ for (auto &cc: Contacts()) {
+ char *szProto = Proto_GetBaseAccountName(cc);
+ if (szProto && (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IM)) {
+ wchar_t name[300];
+ mir_snwprintf(name, L"%s (%S)", Clist_GetContactDisplayName(cc), szProto);
+ int index = m_contacts.AddString(name, cc);
+ if (hContact == cc)
+ m_contacts.SetCurSel(index);
}
}
- CheckDlgButton(hwnd, IDC_CHECK1, (statusFlag & ANY) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwnd, IDC_CHECK2, (statusFlag & ONLINE) >> 1 ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwnd, IDC_CHECK3, (statusFlag & AWAY) >> 2 ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwnd, IDC_CHECK4, (statusFlag & NA) >> 3 ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwnd, IDC_CHECK5, (statusFlag & OCCUPIED) >> 4 ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwnd, IDC_CHECK6, (statusFlag & DND) >> 5 ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwnd, IDC_CHECK7, (statusFlag & FFC) >> 6 ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwnd, IDC_CHECK8, (statusFlag & INVISIBLE) >> 7 ? BST_CHECKED : BST_UNCHECKED);
+
+ return true;
}
-void deletePounce(MCONTACT hContact)
+void CBuddyPounceDlg::onChange_Simple(CCtrlCheck *)
{
+ if (!m_bInitialized) return;
+
+ (new CBuddyPounceSimpleDlg(hContact))->Create();
+
+ OnApply();
+ Close();
+}
+
+void CBuddyPounceDlg::onClick_Delete(CCtrlButton *)
+{
+ edtMessage.SetText(L"");
+ onChanged_Message(0);
+
g_plugin.delSetting(hContact, "PounceMsg");
g_plugin.delSetting(hContact, "SendIfMyStatusIsFLAG");
g_plugin.delSetting(hContact, "SendIfTheirStatusIsFLAG");
@@ -181,419 +127,72 @@ void deletePounce(MCONTACT hContact) g_plugin.delSetting(hContact, "FileToSend");
}
-INT_PTR CALLBACK BuddyPounceSimpleDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+void CBuddyPounceDlg::onClick_Default(CCtrlButton *)
{
- MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- wchar_t msg[1024];
-
- switch (uMsg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwnd);
- hContact = lParam;
- SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lParam);
-
- getDefaultMessage(hwnd, IDC_MESSAGE, hContact);
- mir_snwprintf(msg, TranslateT("The Message (%d Characters)"), GetWindowTextLength(GetDlgItem(hwnd, IDC_MESSAGE)));
- SetDlgItemText(hwnd, GRP_MSG, msg);
- return FALSE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_MESSAGE:
- if (HIWORD(wParam) == EN_CHANGE) {
- int length = GetWindowTextLength(GetDlgItem(hwnd, IDC_MESSAGE));
- mir_snwprintf(msg, TranslateT("The Message (%d Characters)"), length);
- SetDlgItemText(hwnd, GRP_MSG, msg);
- }
- break;
-
- case IDC_ADVANCED:
- // fall through
-
- case IDOK:
- {
- int length = GetWindowTextLength(GetDlgItem(hwnd, IDC_MESSAGE)) + 1;
- if (length > 1) {
- wchar_t *text = (wchar_t*)_alloca(length * sizeof(wchar_t));
- GetDlgItemText(hwnd, IDC_MESSAGE, text, length);
- g_plugin.setWString(hContact, "PounceMsg", text);
- }
- else g_plugin.delSetting(hContact, "PounceMsg");
- }
- // fall through
- case IDCANCEL:
- if (LOWORD(wParam) == IDC_ADVANCED)
- CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_POUNCE), nullptr, BuddyPounceDlgProc, GetWindowLongPtr(hwnd, GWLP_USERDATA));
- DestroyWindow(hwnd);
- }
- break;
- }
- return FALSE;
+ getDefaultMessage(m_hwnd, IDC_MESSAGE, hContact);
+ onChanged_Message(0);
+
+ g_plugin.setWord(hContact, "SendIfMyStatusIsFLAG", g_plugin.getWord("SendIfMyStatusIsFLAG", 0));
+ g_plugin.setWord(hContact, "SendIfTheirStatusIsFLAG", g_plugin.getWord("SendIfTheirStatusIsFLAG", 0));
+ g_plugin.setByte(hContact, "Reuse", g_plugin.getByte("Reuse", 0));
+ g_plugin.setByte(hContact, "GiveUpDays", g_plugin.getByte("GiveUpDays", 0));
+ g_plugin.setDword(hContact, "GiveUpDate", g_plugin.getDword("GiveUpDate", 0));
+ g_plugin.setWord(hContact, "ConfirmTimeout", g_plugin.getWord("ConfirmTimeout", 0));
}
-INT_PTR CALLBACK BuddyPounceDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- windowInfo *wi = (windowInfo *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- wchar_t msg[1024];
-
- switch (uMsg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwnd);
- wi = (windowInfo *)mir_alloc(sizeof(windowInfo));
- wi->hContact = lParam;
- wi->SendIfMy = nullptr;
- wi->SendWhenThey = nullptr;
- SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)wi);
- getDefaultMessage(hwnd, IDC_MESSAGE, wi->hContact);
-
- mir_snwprintf(msg, TranslateT("The Message (%d Characters)"), GetWindowTextLength(GetDlgItem(hwnd, IDC_MESSAGE)));
- SetDlgItemText(hwnd, GRP_MSG, msg);
-
- populateSettingsList(GetDlgItem(hwnd, IDC_SETTINGS));
- populateContacts(wi->hContact, GetDlgItem(hwnd, IDC_CONTACTS));
- SendDlgItemMessage(hwnd, IDC_SPIN, UDM_SETRANGE, 0, (LPARAM)MAKELONG((short)1024, (short)0));
- g_plugin.setByte(wi->hContact, "LastSetting", 0);
- return FALSE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_MESSAGE:
- if (HIWORD(wParam) == EN_CHANGE) {
- int length = GetWindowTextLength(GetDlgItem(hwnd, IDC_MESSAGE));
- mir_snwprintf(msg, TranslateT("The Message (%d Characters)"), length);
- SetDlgItemText(hwnd, GRP_MSG, msg);
- }
- break;
-
- case IDC_SIMPLE:
- case IDOK:
- {
- MCONTACT hContact = (MCONTACT)SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_GETITEMDATA, SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_GETCURSEL, 0, 0), 0);
- int length = GetWindowTextLength(GetDlgItem(hwnd, IDC_MESSAGE)) + 1;
- if (length > 1) {
- wchar_t *text = (wchar_t *)mir_alloc(length * sizeof(wchar_t));
- if (!text) {
- msg(TranslateT("Couldn't allocate enough memory"), L"");
- break;
- }
- GetDlgItemText(hwnd, IDC_MESSAGE, text, length);
- g_plugin.setWString(hContact, "PounceMsg", text);
- mir_free(text);
- }
- else g_plugin.delSetting(hContact, "PounceMsg");
- saveLastSetting(hContact, hwnd);
- }
- if (LOWORD(wParam) == IDC_SIMPLE)
- CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_POUNCE_SIMPLE), nullptr, BuddyPounceSimpleDlgProc, (LPARAM)((windowInfo *)GetWindowLongPtr(hwnd, GWLP_USERDATA))->hContact);
- __fallthrough;
-
- case IDCANCEL:
- if (wi->SendIfMy) DestroyWindow(wi->SendIfMy);
- if (wi->SendWhenThey) DestroyWindow(wi->SendWhenThey);
- mir_free(wi);
- DestroyWindow(hwnd);
- break;
-
- case IDC_DELETE:
- deletePounce(wi->hContact);
- SetDlgItemText(hwnd, IDC_MESSAGE, L"");
- SetDlgItemText(hwnd, GRP_MSG, TranslateT("The Message (0 Characters)"));
- break;
-
- case IDC_DEFAULT:
- getDefaultMessage(hwnd, IDC_MESSAGE, wi->hContact);
-
- mir_snwprintf(msg, TranslateT("The Message (%d Characters)"), GetWindowTextLength(GetDlgItem(hwnd, IDC_MESSAGE)));
- SetDlgItemText(hwnd, GRP_MSG, msg);
-
- g_plugin.setWord(wi->hContact, "SendIfMyStatusIsFLAG", g_plugin.getWord("SendIfMyStatusIsFLAG", 0));
- g_plugin.setWord(wi->hContact, "SendIfTheirStatusIsFLAG", g_plugin.getWord("SendIfTheirStatusIsFLAG", 0));
- g_plugin.setByte(wi->hContact, "Reuse", g_plugin.getByte("Reuse", 0));
- g_plugin.setByte(wi->hContact, "GiveUpDays", g_plugin.getByte("GiveUpDays", 0));
- g_plugin.setDword(wi->hContact, "GiveUpDate", g_plugin.getDword("GiveUpDate", 0));
- g_plugin.setWord(wi->hContact, "ConfirmTimeout", g_plugin.getWord("ConfirmTimeout", 0));
- break;
-
- case IDC_SETTINGS:
- if (HIWORD(wParam) == LBN_SELCHANGE) {
- int item = SendDlgItemMessage(hwnd, IDC_SETTINGS, LB_GETCURSEL, 0, 0);
- wchar_t temp[5];
- saveLastSetting(wi->hContact, hwnd);
- hideAll(hwnd);
- switch (item) {
- case 0: // Send If My Status Is...
- statusModes(wi, 1);
- break;
- case 1: // Send If They Change status to
- statusModes(wi, 0);
- break;
- case 3: // Reuse Pounce
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGMSG), SW_SHOW);
- SetDlgItemText(hwnd, IDC_SETTINGMSG, TranslateT("Reuse this message? (0 to use it once)"));
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGMSG2), SW_SHOW);
- SetDlgItemText(hwnd, IDC_SETTINGMSG2, TranslateT("Times"));
- SetDlgItemText(hwnd, IDC_SETTINGNUMBER, _itow(g_plugin.getByte(wi->hContact, "Reuse", 0), temp, 10));
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGNUMBER), SW_SHOW);
- ShowWindow(GetDlgItem(hwnd, IDC_SPIN), SW_SHOW);
- break;
- case 4: // Give Up delay
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGMSG), SW_SHOW);
- SetDlgItemText(hwnd, IDC_SETTINGMSG, TranslateT("Give up after... (0 to not give up)"));
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGMSG2), SW_SHOW);
- SetDlgItemText(hwnd, IDC_SETTINGMSG2, TranslateT("Days"));
- SetDlgItemText(hwnd, IDC_SETTINGNUMBER, _itow(g_plugin.getByte(wi->hContact, "GiveUpDays", 0), temp, 10));
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGNUMBER), SW_SHOW);
- ShowWindow(GetDlgItem(hwnd, IDC_SPIN), SW_SHOW);
- break;
- case 5: // confirm window
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGMSG), SW_SHOW);
- SetDlgItemText(hwnd, IDC_SETTINGMSG, TranslateT("Show confirmation window? (0 to not Show)"));
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGMSG2), SW_SHOW);
- SetDlgItemText(hwnd, IDC_SETTINGMSG2, TranslateT("Seconds to wait before sending"));
- SetDlgItemText(hwnd, IDC_SETTINGNUMBER, _itow(g_plugin.getWord(wi->hContact, "ConfirmTimeout", 0), temp, 10));
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGNUMBER), SW_SHOW);
- ShowWindow(GetDlgItem(hwnd, IDC_SPIN), SW_SHOW);
- break;
- }
- g_plugin.setByte(wi->hContact, "LastSetting", (BYTE)item);
- }
- }
- break;
- }
- return FALSE;
-}
+/////////////////////////////////////////////////////////////////////////////////////////
+// Pounce send confirmation dialog
-INT_PTR CALLBACK BuddyPounceOptionsDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+class CPounceSentDlg : public CDlgBase
{
- wchar_t msg[1024];
-
- switch (uMsg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwnd);
- {
- windowInfo *wi = (windowInfo *)mir_alloc(sizeof(windowInfo));
- wi->hContact = 0;
- wi->SendIfMy = nullptr;
- wi->SendWhenThey = nullptr;
- SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)wi);
-
- getDefaultMessage(hwnd, IDC_MESSAGE, wi->hContact);
- mir_snwprintf(msg, TranslateT("The Message (%d Characters)"), GetWindowTextLength(GetDlgItem(hwnd, IDC_MESSAGE)));
- SetDlgItemText(hwnd, GRP_MSG, msg);
- populateSettingsList(GetDlgItem(hwnd, IDC_SETTINGS));
- SendDlgItemMessage(hwnd, IDC_SPIN, UDM_SETRANGE, 0, (LPARAM)MAKELONG((short)1024, (short)0));
- CheckDlgButton(hwnd, IDC_USEADVANCED, g_plugin.getByte("UseAdvanced", 0) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwnd, IDC_SHOWDELIVERYMSGS, g_plugin.getByte("ShowDeliveryMessages", 1) ? BST_CHECKED : BST_UNCHECKED);
- g_plugin.setByte(wi->hContact, "LastSetting", 0);
- }
- return FALSE;
-
- case WM_NOTIFY:
- switch (((LPNMHDR)lParam)->idFrom) {
- case 0:
- switch (((LPNMHDR)lParam)->code) {
- case PSN_APPLY:
- windowInfo * wi = (windowInfo *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- MCONTACT hContact = ((windowInfo *)GetWindowLongPtr(hwnd, GWLP_USERDATA))->hContact;
- int length = GetWindowTextLength(GetDlgItem(hwnd, IDC_MESSAGE)) + 1;
- if (length > 1) {
- wchar_t *text = (wchar_t*)mir_alloc(length * sizeof(wchar_t));
- if (!text) {
- msg(TranslateT("Couldn't allocate enough memory"), L"");
- break;
- }
- GetDlgItemText(hwnd, IDC_MESSAGE, text, length);
- g_plugin.setWString(hContact, "PounceMsg", text);
- mir_free(text);
- }
- else g_plugin.delSetting(hContact, "PounceMsg");
- g_plugin.setByte("UseAdvanced", (BYTE)IsDlgButtonChecked(hwnd, IDC_USEADVANCED));
- g_plugin.setByte("ShowDeliveryMessages", (BYTE)IsDlgButtonChecked(hwnd, IDC_SHOWDELIVERYMSGS));
-
- if (wi->SendIfMy) DestroyWindow(wi->SendIfMy);
- if (wi->SendWhenThey) DestroyWindow(wi->SendWhenThey);
- }
- }
- break;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_MESSAGE:
- if (HIWORD(wParam) == EN_CHANGE) {
- int length = GetWindowTextLength(GetDlgItem(hwnd, IDC_MESSAGE));
- mir_snwprintf(msg, TranslateT("The Message (%d Characters)"), length);
- SetDlgItemText(hwnd, GRP_MSG, msg);
- SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
- }
- break;
-
- case IDC_SHOWDELIVERYMSGS:
- case IDC_USEADVANCED:
- SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
- break;
-
- case IDC_SETTINGS:
- if (HIWORD(wParam) == LBN_SELCHANGE) {
- windowInfo *wi = (windowInfo *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- int item = SendDlgItemMessage(hwnd, IDC_SETTINGS, LB_GETCURSEL, 0, 0);
- wchar_t temp[5];
- SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
- saveLastSetting(wi->hContact, hwnd);
- hideAll(hwnd);
- switch (item) {
- case 0: // Send If My Status Is...
- statusModes(wi, 1);
- break;
- case 1: // Send If They Change status to
- statusModes(wi, 0);
- break;
- case 3: // Reuse Pounce
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGMSG), SW_SHOW);
- SetDlgItemText(hwnd, IDC_SETTINGMSG, TranslateT("Reuse this message? (0 to use it once)"));
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGMSG2), SW_SHOW);
- SetDlgItemText(hwnd, IDC_SETTINGMSG2, TranslateT("Times"));
- SetDlgItemText(hwnd, IDC_SETTINGNUMBER, _itow(g_plugin.getByte(wi->hContact, "Reuse", 0), temp, 10));
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGNUMBER), SW_SHOW);
- ShowWindow(GetDlgItem(hwnd, IDC_SPIN), SW_SHOW);
- break;
- case 4: // Give Up delay
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGMSG), SW_SHOW);
- SetDlgItemText(hwnd, IDC_SETTINGMSG, TranslateT("Give up after... (0 to not give up)"));
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGMSG2), SW_SHOW);
- SetDlgItemText(hwnd, IDC_SETTINGMSG2, TranslateT("Days"));
- SetDlgItemText(hwnd, IDC_SETTINGNUMBER, _itow(g_plugin.getByte(wi->hContact, "GiveUpDays", 0), temp, 10));
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGNUMBER), SW_SHOW);
- ShowWindow(GetDlgItem(hwnd, IDC_SPIN), SW_SHOW);
- break;
- case 5: // confirm window
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGMSG), SW_SHOW);
- SetDlgItemText(hwnd, IDC_SETTINGMSG, TranslateT("Show confirmation window? (0 to not Show)"));
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGMSG2), SW_SHOW);
- SetDlgItemText(hwnd, IDC_SETTINGMSG2, TranslateT("Seconds to wait before sending"));
- SetDlgItemText(hwnd, IDC_SETTINGNUMBER, _itow(g_plugin.getWord(wi->hContact, "ConfirmTimeout", 0), temp, 10));
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGNUMBER), SW_SHOW);
- ShowWindow(GetDlgItem(hwnd, IDC_SPIN), SW_SHOW);
- break;
- }
- g_plugin.setByte(wi->hContact, "LastSetting", (BYTE)item);
- }
- }
- break;
- }
- return FALSE;
-}
+ bool m_bSuccess;
+ MCONTACT m_hContact;
-INT_PTR CALLBACK SendPounceDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- SendPounceDlgProcStruct *spdps = (SendPounceDlgProcStruct *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
-
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwnd);
- spdps = (SendPounceDlgProcStruct*)lParam;
- spdps->timer = g_plugin.getWord(spdps->hContact, "ConfirmTimeout");
- SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)spdps);
- {
- DBVARIANT dbv;
- if (g_plugin.getWString(spdps->hContact, "PounceMsg", &dbv))
- DestroyWindow(hwnd);
- else {
- SetDlgItemText(hwnd, IDC_MESSAGE, dbv.pwszVal);
- db_free(&dbv);
- }
- }
- SetTimer(hwnd, 1, 1000, nullptr);
- SendMessage(hwnd, WM_TIMER, 0, 0);
- break;
+ CCtrlEdit edtMessage;
+
+public:
+ CPounceSentDlg(MCONTACT hContact, bool bSuccess) :
+ CDlgBase(g_plugin, IDD_CONFIRMSEND),
+ m_bSuccess(bSuccess),
+ m_hContact(hContact),
+ edtMessage(this, IDC_MESSAGE)
+ {}
- case WM_TIMER:
+ bool OnInitDialog() override
{
- wchar_t message[1024];
- mir_snwprintf(message, TranslateT("Pounce being sent to %s in %d seconds"), Clist_GetContactDisplayName(spdps->hContact), spdps->timer);
- SetDlgItemText(hwnd, LBL_CONTACT, message);
- }
- spdps->timer--;
- if (spdps->timer < 0) {
- KillTimer(hwnd, 1);
- SendPounce(spdps->message, spdps->hContact);
- DestroyWindow(hwnd);
- }
- break;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDOK:
- KillTimer(hwnd, 1);
- SendPounce(spdps->message, spdps->hContact);
- // fall through
- case IDCANCEL:
- KillTimer(hwnd, 1);
- DestroyWindow(hwnd);
- break;
- }
- break;
+ ptrW wszMessage(g_plugin.getWStringA(m_hContact, "PounceMsg"));
+ if (wszMessage == nullptr)
+ return false;
- case WM_DESTROY:
- mir_free(spdps->message);
- mir_free(spdps);
- break;
- }
- return 0;
-}
+ edtMessage.SetText(wszMessage);
-INT_PTR CALLBACK PounceSentDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA);
-
- switch (msg) {
- case WM_INITDIALOG:
- SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lParam);
- TranslateDialogDefault(hwnd);
- hContact = lParam;
- {
- DBVARIANT dbv;
- if (g_plugin.getWString(hContact, "PounceMsg", &dbv))
- DestroyWindow(hwnd);
- else {
- SetDlgItemText(hwnd, IDC_MESSAGE, dbv.pwszVal);
- db_free(&dbv);
- }
+ wchar_t msg[256];
+ if (m_bSuccess) {
+ mir_snwprintf(msg, TranslateT("Message successfully sent to %s"), Clist_GetContactDisplayName(m_hContact));
+ SetDlgItemText(m_hwnd, IDOK, TranslateT("OK"));
+ ShowWindow(GetDlgItem(m_hwnd, IDCANCEL), 0);
}
- break;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDOK:
- {
- wchar_t text[2048];
- GetDlgItemText(hwnd, IDOK, text, _countof(text));
- if (!mir_wstrcmp(text, TranslateT("Retry"))) {
- GetDlgItemText(hwnd, IDC_MESSAGE, text, _countof(text));
- SendPounce(text, hContact);
- }
+ else {
+ mir_snwprintf(msg, TranslateT("Message failed to send to %s"), Clist_GetContactDisplayName(m_hContact));
+ SetDlgItemText(m_hwnd, IDOK, TranslateT("Retry"));
}
- // fall through
- case IDCANCEL:
- DestroyWindow(hwnd);
+ SetDlgItemText(m_hwnd, LBL_CONTACT, msg);
+ SetWindowText(m_hwnd, TranslateT(modFullname));
+ return true;
+ }
+
+ bool OnApply() override
+ {
+ if (!m_bSuccess) {
+ ptrW wszMessage(edtMessage.GetText());
+ if (wszMessage)
+ SendPounce(wszMessage, m_hContact);
}
- break;
+ return true;
}
- return 0;
-}
+};
void CreateMessageAcknowlegedWindow(MCONTACT hContact, int SentSuccess)
{
- HWND hwnd = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_CONFIRMSEND), nullptr, PounceSentDlgProc, hContact);
- wchar_t msg[256];
- if (SentSuccess) {
- mir_snwprintf(msg, TranslateT("Message successfully sent to %s"), Clist_GetContactDisplayName(hContact));
- SetDlgItemText(hwnd, IDOK, TranslateT("OK"));
- ShowWindow(GetDlgItem(hwnd, IDCANCEL), 0);
- }
- else {
- mir_snwprintf(msg, TranslateT("Message failed to send to %s"), Clist_GetContactDisplayName(hContact));
- SetDlgItemText(hwnd, IDOK, TranslateT("Retry"));
- }
- SetDlgItemText(hwnd, LBL_CONTACT, msg);
- SetWindowText(hwnd, TranslateT(modFullname));
+ (new CPounceSentDlg(hContact, SentSuccess != 0))->Create();
}
diff --git a/plugins/BuddyPounce/src/main.cpp b/plugins/BuddyPounce/src/main.cpp index 6cb099bfc7..d467353a70 100644 --- a/plugins/BuddyPounce/src/main.cpp +++ b/plugins/BuddyPounce/src/main.cpp @@ -21,8 +21,11 @@ PLUGININFOEX pluginInfoEx = { };
CMPlugin::CMPlugin() :
- PLUGIN<CMPlugin>("BuddyPounce", pluginInfoEx)
-{}
+ PLUGIN<CMPlugin>("BuddyPounce", pluginInfoEx),
+ bUseAdvanced(m_szModuleName, "UseAdvanced", false),
+ bShowDelivery(m_szModuleName, "ShowDeliveryMessages", true)
+{
+}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -32,8 +35,9 @@ int MsgAck(WPARAM, LPARAM lParam) if (ack && ack->type == ACKTYPE_MESSAGE) {
if (ack->hProcess == (HANDLE)WindowList_Find(hWindowList, ack->hContact)) {
- if (g_plugin.getByte("ShowDeliveryMessages", 1))
+ if (g_plugin.bShowDelivery)
CreateMessageAcknowlegedWindow(ack->hContact, ack->result == ACKRESULT_SUCCESS);
+
if (ack->result == ACKRESULT_SUCCESS) {
// wrtie it to the DB
DBVARIANT dbv;
@@ -64,20 +68,19 @@ int MsgAck(WPARAM, LPARAM lParam) return 0;
}
-int PrebuildContactMenu(WPARAM hContact, LPARAM)
+static int PrebuildContactMenu(WPARAM hContact, LPARAM)
{
Menu_ShowItem(g_hMenuItem, (CallProtoService(Proto_GetBaseAccountName(hContact), PS_GETCAPS, PFLAGNUM_1) & PF1_IM) != 0);
return 0;
}
-int BuddyPounceOptInit(WPARAM wParam, LPARAM)
+static int BuddyPounceOptInit(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = {};
- odp.flags = ODPF_BOLDGROUPS | ODPF_UNICODE;
- odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS);
- odp.szGroup.w = LPGENW("Message sessions");
- odp.szTitle.w = LPGENW("Buddy Pounce");
- odp.pfnDlgProc = BuddyPounceOptionsDlgProc;
+ odp.flags = ODPF_BOLDGROUPS;
+ odp.szGroup.a = LPGEN("Message sessions");
+ odp.szTitle.a = LPGEN("Buddy Pounce");
+ odp.pDialog = new COptionsDlg(IDD_OPTIONS);
g_plugin.addOptions(wParam, &odp);
return 0;
}
@@ -121,7 +124,56 @@ void SendPounce(wchar_t *text, MCONTACT hContact) WindowList_Add(hWindowList, (HWND)hSendId, hContact);
}
-int UserOnlineSettingChanged(WPARAM hContact, LPARAM lParam)
+/////////////////////////////////////////////////////////////////////////////////////////
+
+class CSendConfirmDlg : public CDlgBase
+{
+ int timeout;
+ MCONTACT hContact;
+ ptrW wszMessage;
+
+ CTimer timer;
+
+public:
+ CSendConfirmDlg(MCONTACT _1, wchar_t *_2) :
+ CDlgBase(g_plugin, IDD_CONFIRMSEND),
+ hContact(_1),
+ wszMessage(_2),
+ timer(this, 1)
+ {
+ timeout = g_plugin.getWord(hContact, "ConfirmTimeout");
+ }
+
+ bool OnInitDialog() override
+ {
+ SetDlgItemText(m_hwnd, IDC_MESSAGE, wszMessage);
+ timer.Start(1000);
+ OnTimer(0);
+ return true;
+ }
+
+ bool OnApply() override
+ {
+ SendPounce(wszMessage, hContact);
+ return true;
+ }
+
+ void onTimer(CTimer *)
+ {
+ wchar_t message[1024];
+ mir_snwprintf(message, TranslateT("Pounce being sent to %s in %d seconds"), Clist_GetContactDisplayName(hContact), timeout);
+ SetDlgItemText(m_hwnd, LBL_CONTACT, message);
+
+ timeout--;
+ if (timeout < 0) {
+ timer.Stop();
+ SendPounce(message, hContact);
+ Close();
+ }
+ }
+};
+
+static int UserOnlineSettingChanged(WPARAM hContact, LPARAM lParam)
{
DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)lParam;
@@ -132,39 +184,34 @@ int UserOnlineSettingChanged(WPARAM hContact, LPARAM lParam) int oldStatus = db_get_w(hContact, "UserOnline", "OldStatus", ID_STATUS_OFFLINE);
if (newStatus != oldStatus && newStatus != ID_STATUS_OFFLINE) {
- DBVARIANT dbv;
- if (!g_plugin.getWString(hContact, "PounceMsg", &dbv) && (dbv.pwszVal[0] != '\0')) {
+ ptrW wszMessage(g_plugin.getWStringA(hContact, "PounceMsg"));
+ if (mir_wstrlen(wszMessage)) {
// check my status
if (statusCheck(g_plugin.getWord(hContact, "SendIfMyStatusIsFLAG", 0), Proto_GetStatus(szProto))
// check the contacts status
&& statusCheck(g_plugin.getWord(hContact, "SendIfTheirStatusIsFLAG", 0), newStatus)) {
// check if we r giving up after x days
if (CheckDate(hContact)) {
- if (g_plugin.getWord(hContact, "ConfirmTimeout", 0)) {
- SendPounceDlgProcStruct *spdps = (SendPounceDlgProcStruct *)mir_alloc(sizeof(SendPounceDlgProcStruct));
- wchar_t *message = mir_wstrdup(dbv.pwszVal); // will get free()ed in the send confirm window proc
- spdps->hContact = hContact;
- spdps->message = message;
- CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_CONFIRMSEND), nullptr, SendPounceDlgProc, (LPARAM)spdps);
- // set the confirmation window to send the msg when the timeout is done
- mir_free(message);
- }
- else SendPounce(dbv.pwszVal, hContact);
+ if (g_plugin.getWord(hContact, "ConfirmTimeout"))
+ (new CSendConfirmDlg(hContact, wszMessage.detach()))->Create();
+ else
+ SendPounce(wszMessage, hContact);
}
}
- db_free(&dbv);
}
}
}
return 0;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
INT_PTR BuddyPounceMenuCommand(WPARAM hContact, LPARAM)
{
- if (g_plugin.getByte("UseAdvanced", 0) || g_plugin.getByte(hContact, "UseAdvanced", 0))
- CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_POUNCE), nullptr, BuddyPounceDlgProc, hContact);
+ if (g_plugin.bUseAdvanced || g_plugin.getByte(hContact, "UseAdvanced"))
+ (new CBuddyPounceDlg(hContact))->Create();
else
- CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_POUNCE_SIMPLE), nullptr, BuddyPounceSimpleDlgProc, hContact);
+ (new CBuddyPounceSimpleDlg(hContact))->Create();
return 0;
}
diff --git a/plugins/BuddyPounce/src/options.cpp b/plugins/BuddyPounce/src/options.cpp new file mode 100644 index 0000000000..df13f1a05b --- /dev/null +++ b/plugins/BuddyPounce/src/options.cpp @@ -0,0 +1,245 @@ +/* +Copyright (C) 2012-21 Miranda NG team (https://miranda-ng.org) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation version 2 +of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "stdafx.h" + +COptionsDlg::COptionsDlg(int dlgId) : + CSuper(dlgId), + m_settings(this, IDC_SETTINGS), + spin(this, IDC_SPIN, 1024), + msg1(this, IDC_SETTINGMSG), + msg2(this, IDC_SETTINGMSG2), + edtNumber(this, IDC_SETTINGNUMBER), + chkAdvanced(this, IDC_USEADVANCED), + chkShowDelivery(this, IDC_SHOWDELIVERYMSGS) +{ + CreateLink(chkAdvanced, g_plugin.bUseAdvanced); + CreateLink(chkShowDelivery, g_plugin.bShowDelivery); + + m_settings.OnSelChange = Callback(this, &COptionsDlg::onSelChange_Settings); +} + +bool COptionsDlg::OnInitDialog() +{ + CSuper::OnInitDialog(); + + m_settings.AddString(TranslateT("Send If My Status Is...")); + m_settings.AddString(TranslateT("Send If They Change Status to...")); + m_settings.AddString(L"----------------------------"); + m_settings.AddString(TranslateT("Reuse Pounce")); + m_settings.AddString(TranslateT("Give Up delay")); + m_settings.AddString(TranslateT("Confirmation Window")); + m_settings.SetCurSel(g_plugin.getByte(hContact, "LastSetting")); + onSelChange_Settings(0); + return true; +} + +bool COptionsDlg::OnApply() +{ + CSuper::OnApply(); + + saveLastSetting(); + return true; +} + +void COptionsDlg::OnDestroy() +{ + if (SendIfMy) + DestroyWindow(SendIfMy); + if (SendWhenThey) + DestroyWindow(SendWhenThey); +} + +void COptionsDlg::onSelChange_Settings(CCtrlListBox*) +{ + if (m_bInitialized) + saveLastSetting(); + + int item = m_settings.GetCurSel(); + switch (item) { + case 0: // Send If My Status Is... + showAll(false); + if (m_bInitialized) + statusModes(true); + break; + + case 1: // Send If They Change status to + showAll(false); + if (m_bInitialized) + statusModes(false); + break; + + case 3: // Reuse Pounce + showAll(true); + msg1.SetText(TranslateT("Reuse this message? (0 to use it once)")); + msg2.SetText(TranslateT("Times")); + edtNumber.SetInt(g_plugin.getByte(hContact, "Reuse")); + break; + + case 4: // Give Up delay + showAll(true); + msg1.SetText(TranslateT("Give up after... (0 to not give up)")); + msg2.SetText(TranslateT("Days")); + edtNumber.SetInt(g_plugin.getByte(hContact, "GiveUpDays")); + break; + + case 5: // confirm window + showAll(true); + msg1.SetText(TranslateT("Show confirmation window? (0 to not Show)")); + msg2.SetText(TranslateT("Seconds to wait before sending")); + edtNumber.SetInt(g_plugin.getWord(hContact, "ConfirmTimeout")); + break; + } + g_plugin.setByte(hContact, "LastSetting", (BYTE)item); + NotifyChange(); +} + +void COptionsDlg::saveLastSetting() +{ + switch (g_plugin.getByte(hContact, "LastSetting", 2)) { + case 3: // Reuse Pounce + g_plugin.setByte(hContact, "Reuse", (BYTE)edtNumber.GetInt()); + break; + case 4: // Give Up delay + g_plugin.setByte(hContact, "GiveUpDays", (BYTE)edtNumber.GetInt()); + g_plugin.setDword(hContact, "GiveUpDate", (DWORD)edtNumber.GetInt() * SECONDSINADAY); + break; + case 5: // confirm window + g_plugin.setWord(hContact, "ConfirmTimeout", (WORD)edtNumber.GetInt()); + break; + } +} + +void COptionsDlg::showAll(bool bShow) +{ + msg1.Show(bShow); + msg2.Show(bShow); + spin.Show(bShow); + edtNumber.Show(bShow); +} + +///////////////////////////////////////////////////////////////////////////////////////// +// Status modes dialog wrapper + +class CStatusModesDlg : public CDlgBase +{ + COptionsDlg *pDlg; + bool isMe; + + CCtrlCheck chk1, chk2, chk3, chk4, chk5, chk6, chk7, chk8; + +public: + CStatusModesDlg(COptionsDlg *_1, bool _2) : + CDlgBase(g_plugin, IDD_STATUSMODES), + pDlg(_1), + isMe(_2), + chk1(this, IDC_CHECK1), + chk2(this, IDC_CHECK2), + chk3(this, IDC_CHECK3), + chk4(this, IDC_CHECK4), + chk5(this, IDC_CHECK5), + chk6(this, IDC_CHECK6), + chk7(this, IDC_CHECK7), + chk8(this, IDC_CHECK8) + { + SetParent(pDlg->GetHwnd()); + } + + bool OnInitDialog() override + { + int statusFlag; + + if (isMe) { + pDlg->SendIfMy = m_hwnd; + statusFlag = g_plugin.getWord(pDlg->hContact, "SendIfMyStatusIsFLAG", 0); + SetCaption(TranslateT("Send If My Status Is")); + chk1.SetText(TranslateT("Any")); + chk2.SetText(TranslateT("Online")); + chk3.SetText(TranslateT("Away")); + chk4.SetText(TranslateT("Not available")); + chk5.SetText(TranslateT("Occupied")); + chk6.SetText(TranslateT("Do not disturb")); + chk7.SetText(TranslateT("Free for chat")); + chk8.SetText(TranslateT("Invisible")); + } + else { + pDlg->SendWhenThey = m_hwnd; + statusFlag = g_plugin.getWord(pDlg->hContact, "SendIfTheirStatusIsFLAG", 0); + SetCaption(TranslateT("Send If Their Status changes")); + chk1.SetText(TranslateT("From Offline")); + chk2.SetText(TranslateT("To Online")); + chk3.SetText(TranslateT("To Away")); + chk4.SetText(TranslateT("To Not available")); + chk5.SetText(TranslateT("To Occupied")); + chk6.SetText(TranslateT("To Do not disturb")); + chk7.SetText(TranslateT("To Free for chat")); + chk8.SetText(TranslateT("To Invisible")); + } + + chk1.SetState((statusFlag & ANY) != 0); + chk2.SetState((statusFlag & ONLINE) != 0); + chk3.SetState((statusFlag & AWAY) != 0); + chk4.SetState((statusFlag & NA) != 0); + chk5.SetState((statusFlag & OCCUPIED) != 0); + chk6.SetState((statusFlag & DND) != 0); + chk7.SetState((statusFlag & FFC) != 0); + chk8.SetState((statusFlag & INVISIBLE) != 0); + return true; + } + + bool OnApply() override + { + int flag = chk1.GetState() + | (chk2.GetState() << 1) + | (chk3.GetState() << 2) + | (chk4.GetState() << 3) + | (chk5.GetState() << 4) + | (chk6.GetState() << 5) + | (chk7.GetState() << 6) + | (chk8.GetState() << 7); + + if (isMe) + g_plugin.setWord(pDlg->hContact, "SendIfMyStatusIsFLAG", flag); + else + g_plugin.setWord(pDlg->hContact, "SendIfTheirStatusIsFLAG", flag); + return true; + } + + void OnDestroy() override + { + if (isMe) + pDlg->SendIfMy = nullptr; + else + pDlg->SendWhenThey = nullptr; + } +}; + +void COptionsDlg::statusModes(bool isMe) +{ + if (isMe) { + if (SendIfMy) + SetForegroundWindow(SendIfMy); + else + (new CStatusModesDlg(this, true))->Create(); + } + else { + if (SendWhenThey) + SetForegroundWindow(SendWhenThey); + else + (new CStatusModesDlg(this, false))->Create(); + } +} diff --git a/plugins/BuddyPounce/src/resource.h b/plugins/BuddyPounce/src/resource.h index d9f13a992e..2502ad5d28 100644 --- a/plugins/BuddyPounce/src/resource.h +++ b/plugins/BuddyPounce/src/resource.h @@ -1,6 +1,6 @@ //{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
-// Used by ..\res\resource.rc
+// Used by W:\miranda-ng\plugins\BuddyPounce\res\resource.rc
//
#define IDC_DELETE 5
#define IDC_DEFAULT 6
@@ -45,8 +45,6 @@ #define IDC_SETTINGMSG 1061
#define IDC_SETTINGNUMBER 1066
#define IDC_SPIN 1067
-//#define IDC_SETTINGTEXT 1068
-//#define IDC_BUTTON 1069
#define IDC_SETTINGS 1075
#define IDC_CONTACTS 1076
#define IDC_ADVANCED 1078
@@ -67,7 +65,7 @@ //
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 112
+#define _APS_NEXT_RESOURCE_VALUE 113
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1098
#define _APS_NEXT_SYMED_VALUE 101
diff --git a/plugins/BuddyPounce/src/stdafx.h b/plugins/BuddyPounce/src/stdafx.h index f3a346aef5..a29e1c1ec9 100644 --- a/plugins/BuddyPounce/src/stdafx.h +++ b/plugins/BuddyPounce/src/stdafx.h @@ -10,10 +10,11 @@ #include <newpluginapi.h>
#include <m_clist.h>
-#include <m_langpack.h>
#include <m_database.h>
-#include <m_protocols.h>
+#include <m_gui.h>
+#include <m_langpack.h>
#include <m_options.h>
+#include <m_protocols.h>
#include <m_protosvc.h>
#include "resource.h"
@@ -22,6 +23,7 @@ //=======================================================
// Definitions
//=======================================================
+
#define modFullname "Buddy Pounce"
#define msg(a,b) MessageBox(0,a,b,MB_OK)
@@ -29,6 +31,8 @@ struct CMPlugin : public PLUGIN<CMPlugin> {
CMPlugin();
+ CMOption<bool> bUseAdvanced, bShowDelivery;
+
int Load() override;
int Unload() override;
};
@@ -46,35 +50,93 @@ struct CMPlugin : public PLUGIN<CMPlugin> #define INVISIBLE 128
//=======================================================
-// Variables
+// Functions
//=======================================================
-struct windowInfo
+// main.c
+void SendPounce(wchar_t* text, MCONTACT hContact);
+
+//dialog.c
+void CreateMessageAcknowlegedWindow(MCONTACT hContact, int SentSuccess);
+
+void getDefaultMessage(HWND hwnd, UINT control, MCONTACT hContact);
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// dialogs
+
+class CBuddyPounceBasicDlg : public CDlgBase
+{
+
+protected:
+ CCtrlEdit edtMessage;
+ MCONTACT hContact = 0;
+
+public:
+ CBuddyPounceBasicDlg(int dlgId);
+
+ bool OnInitDialog() override;
+ bool OnApply() override;
+
+ void onChanged_Message(CCtrlEdit *);
+};
+
+class COptionsDlg : public CBuddyPounceBasicDlg
{
- MCONTACT hContact;
- HWND SendIfMy;
- HWND SendWhenThey;
+ friend class CStatusModesDlg;
+ typedef CBuddyPounceBasicDlg CSuper;
+
+ CCtrlSpin spin;
+ CCtrlEdit edtNumber;
+ CCtrlBase msg1, msg2;
+ CCtrlCheck chkAdvanced, chkShowDelivery;
+ CCtrlListBox m_settings;
+
+ void saveLastSetting();
+ void showAll(bool bShow);
+ void statusModes(bool isMe);
+
+protected:
+ HWND SendIfMy = 0;
+ HWND SendWhenThey = 0;
+
+public:
+ COptionsDlg(int dlgId);
+
+ bool OnInitDialog() override;
+ bool OnApply() override;
+ void OnDestroy() override;
+
+ void onSelChange_Settings(CCtrlListBox *);
};
-struct SendPounceDlgProcStruct
+class CBuddyPounceDlg : public COptionsDlg
{
- MCONTACT hContact;
- int timer;
- wchar_t *message;
+ typedef COptionsDlg CSuper;
+
+ CCtrlCombo m_contacts;
+ CCtrlCheck chkSimple;
+ CCtrlButton btnDelete, btnDefault;
+
+public:
+ CBuddyPounceDlg(MCONTACT);
+
+ bool OnInitDialog() override;
+
+ void onClick_Delete(CCtrlButton *);
+ void onClick_Default(CCtrlButton *);
+
+ void onChange_Simple(CCtrlCheck *);
};
-//=======================================================
-// Functions
-//=======================================================
+class CBuddyPounceSimpleDlg : public CBuddyPounceBasicDlg
+{
+ CCtrlButton btnAdvanced;
+ typedef CBuddyPounceBasicDlg CSuper;
-// main.c
-void SendPounce(wchar_t* text, MCONTACT hContact);
+public:
+ CBuddyPounceSimpleDlg(MCONTACT);
-//dialog.c
-INT_PTR CALLBACK BuddyPounceDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
-INT_PTR CALLBACK BuddyPounceSimpleDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
-INT_PTR CALLBACK BuddyPounceOptionsDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
-INT_PTR CALLBACK SendPounceDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
-void CreateMessageAcknowlegedWindow(MCONTACT hContact, int SentSuccess);
+ void onClick_Advanced(CCtrlButton *);
+};
#endif //_COMMONHEADERS_H
\ No newline at end of file diff --git a/plugins/BuddyPounce/src/version.h b/plugins/BuddyPounce/src/version.h index 49843db69b..e565ca2805 100644 --- a/plugins/BuddyPounce/src/version.h +++ b/plugins/BuddyPounce/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 3 -#define __RELEASE_NUM 2 -#define __BUILD_NUM 3 +#define __RELEASE_NUM 3 +#define __BUILD_NUM 0 #include <stdver.h> |