From 55dc3a99af44bb97931bdeca9122d0d62f7b183f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Sun, 25 Oct 2015 11:41:14 +0000 Subject: Dummy: Support for sending messages (with option to enable it) git-svn-id: http://svn.miranda-ng.org/main/trunk@15614 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Dummy/res/resource.aps | Bin 3476 -> 3608 bytes protocols/Dummy/res/resource.rc | 6 ++++-- protocols/Dummy/src/dummy.h | 9 +++++++++ protocols/Dummy/src/dummy_options.cpp | 7 +++++++ protocols/Dummy/src/dummy_proto.cpp | 27 +++++++++++++++++++++------ protocols/Dummy/src/dummy_proto.h | 2 ++ protocols/Dummy/src/resource.h | 3 ++- 7 files changed, 45 insertions(+), 9 deletions(-) (limited to 'protocols') diff --git a/protocols/Dummy/res/resource.aps b/protocols/Dummy/res/resource.aps index b342d02388..10cecfb374 100644 Binary files a/protocols/Dummy/res/resource.aps and b/protocols/Dummy/res/resource.aps differ diff --git a/protocols/Dummy/res/resource.rc b/protocols/Dummy/res/resource.rc index 19b1fb4949..7d7ef55679 100644 --- a/protocols/Dummy/res/resource.rc +++ b/protocols/Dummy/res/resource.rc @@ -23,7 +23,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US // Dialog // -IDD_ACCMGRUI DIALOGEX 0, 0, 186, 122 +IDD_ACCMGRUI DIALOGEX 0, 0, 186, 144 STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD EXSTYLE WS_EX_CONTROLPARENT FONT 8, "MS Shell Dlg", 0, 0, 0x1 @@ -37,6 +37,8 @@ BEGIN EDITTEXT IDC_ID_TEXT,95,63,90,12,ES_AUTOHSCROLL LTEXT "Visible name of unique identifier of contacts",IDC_STATIC,10,79,175,18 LTEXT "Restart is required to apply these changes.",IDC_STATIC,0,105,185,8 + CONTROL "Allow sending messages to contacts",IDC_ALLOW_SENDING, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,0,121,185,10 END @@ -79,7 +81,7 @@ BEGIN VERTGUIDE, 10 VERTGUIDE, 95 VERTGUIDE, 185 - BOTTOMMARGIN, 93 + BOTTOMMARGIN, 138 END END #endif // APSTUDIO_INVOKED diff --git a/protocols/Dummy/src/dummy.h b/protocols/Dummy/src/dummy.h index 34f2ad3a7d..d9e22c2736 100644 --- a/protocols/Dummy/src/dummy.h +++ b/protocols/Dummy/src/dummy.h @@ -22,6 +22,15 @@ extern HINSTANCE hInst; #define DUMMY_ID_TEMPLATE "Template" #define DUMMY_ID_TEXT "UniqueIdText" #define DUMMY_ID_SETTING "UniqueIdSetting" +#define DUMMY_KEY_ALLOW_SENDING "AllowSending" + +struct message_data +{ + message_data(MCONTACT hContact, const std::string &msg, int msgid) : hContact(hContact), msg(msg), msgid(msgid) {} + MCONTACT hContact; + std::string msg; + int msgid; +}; typedef struct { const char *name; diff --git a/protocols/Dummy/src/dummy_options.cpp b/protocols/Dummy/src/dummy_options.cpp index aa6cb6d798..7f86602d08 100644 --- a/protocols/Dummy/src/dummy_options.cpp +++ b/protocols/Dummy/src/dummy_options.cpp @@ -56,6 +56,9 @@ INT_PTR CALLBACK DummyAccountProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM int templateId = ppro->getTemplateId(); SendDlgItemMessage(hwndDlg, IDC_TEMPLATE, CB_SETCURSEL, templateId, 0); + boolean allowSending = ppro->getByte(DUMMY_KEY_ALLOW_SENDING, 0); + CheckDlgButton(hwndDlg, IDC_ALLOW_SENDING, allowSending ? BST_CHECKED : BST_UNCHECKED); + onTemplateSelected(hwndDlg, ppro, templateId); } return TRUE; @@ -75,6 +78,8 @@ INT_PTR CALLBACK DummyAccountProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; } + default: + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } break; @@ -93,6 +98,8 @@ INT_PTR CALLBACK DummyAccountProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM GetDlgItemTextA(hwndDlg, IDC_ID_SETTING, str, _countof(str)); ppro->setString(DUMMY_ID_SETTING, str); } + + ppro->setByte(DUMMY_KEY_ALLOW_SENDING, IsDlgButtonChecked(hwndDlg, IDC_ALLOW_SENDING)); } break; diff --git a/protocols/Dummy/src/dummy_proto.cpp b/protocols/Dummy/src/dummy_proto.cpp index 4e9e171cb5..533b137199 100644 --- a/protocols/Dummy/src/dummy_proto.cpp +++ b/protocols/Dummy/src/dummy_proto.cpp @@ -17,11 +17,21 @@ along with this program. If not, see . #include "stdafx.h" -void CDummyProto::SendMsgAck(void *param) +void CDummyProto::SendMsgAck(void *p) { - MCONTACT hContact = (UINT_PTR)param; + if (p == NULL) + return; + + message_data *data = static_cast(p); + Sleep(100); - ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)0, (LPARAM)Translate("Dummy protocol is too dumb to send messages.")); + + if (getByte(DUMMY_KEY_ALLOW_SENDING, 0)) + ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)data->msgid, 0); + else + ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)data->msgid, (LPARAM)Translate("This Dummy account has disabled sending messages. Enable it in account options.")); + + delete data; } void CDummyProto::SearchIdAckThread(void *targ) @@ -49,6 +59,8 @@ CDummyProto::CDummyProto(const char *szModuleName, const TCHAR *ptszUserName) : { CreateProtoService(PS_CREATEACCMGRUI, &CDummyProto::SvcCreateAccMgrUI); + msgid = 0; + uniqueIdText[0] = '\0'; uniqueIdSetting[0] = '\0'; @@ -116,10 +128,13 @@ DWORD_PTR CDummyProto::GetCaps(int type, MCONTACT) ////////////////////////////////////////////////////////////////////////////// -int CDummyProto::SendMsg(MCONTACT hContact, int, const char*) +int CDummyProto::SendMsg(MCONTACT hContact, int, const char *msg) { - ForkThread(&CDummyProto::SendMsgAck, (void*)hContact); - return 0; + std::string message = msg; + unsigned int id = InterlockedIncrement(&this->msgid); + + ForkThread(&CDummyProto::SendMsgAck, new message_data(hContact, message, id)); + return id; } int CDummyProto::SetStatus(int) diff --git a/protocols/Dummy/src/dummy_proto.h b/protocols/Dummy/src/dummy_proto.h index c236c31093..d2da9b0d61 100644 --- a/protocols/Dummy/src/dummy_proto.h +++ b/protocols/Dummy/src/dummy_proto.h @@ -53,4 +53,6 @@ struct CDummyProto : public PROTO char uniqueIdSetting[100]; int getTemplateId(); + + volatile unsigned int msgid; }; diff --git a/protocols/Dummy/src/resource.h b/protocols/Dummy/src/resource.h index bf5d6ff711..f9405505ad 100644 --- a/protocols/Dummy/src/resource.h +++ b/protocols/Dummy/src/resource.h @@ -6,6 +6,7 @@ #define IDC_ID_TEXT 1030 #define IDC_ID_SETTING 1031 #define IDC_TEMPLATE 1032 +#define IDC_ALLOW_SENDING 1033 // Next default values for new objects // @@ -14,7 +15,7 @@ #define _APS_NO_MFC 1 #define _APS_NEXT_RESOURCE_VALUE 102 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1033 +#define _APS_NEXT_CONTROL_VALUE 1034 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif -- cgit v1.2.3