diff options
-rw-r--r-- | protocols/WhatsAppWeb/res/whatsapp.rc | 16 | ||||
-rw-r--r-- | protocols/WhatsAppWeb/src/options.cpp | 9 | ||||
-rw-r--r-- | protocols/WhatsAppWeb/src/proto.cpp | 9 | ||||
-rw-r--r-- | protocols/WhatsAppWeb/src/proto.h | 11 | ||||
-rw-r--r-- | protocols/WhatsAppWeb/src/resource.h | 6 | ||||
-rw-r--r-- | protocols/WhatsAppWeb/src/server.cpp | 9 | ||||
-rw-r--r-- | protocols/WhatsAppWeb/src/utils.cpp | 48 |
7 files changed, 93 insertions, 15 deletions
diff --git a/protocols/WhatsAppWeb/res/whatsapp.rc b/protocols/WhatsAppWeb/res/whatsapp.rc index b133c6d5f6..1d32f6b828 100644 --- a/protocols/WhatsAppWeb/res/whatsapp.rc +++ b/protocols/WhatsAppWeb/res/whatsapp.rc @@ -39,10 +39,12 @@ STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD EXSTYLE WS_EX_CONTROLPARENT FONT 8, "MS Shell Dlg", 400, 0, 0x0 BEGIN - LTEXT "Default group:",IDC_STATIC,4,5,55,10 - EDITTEXT IDC_DEFGROUP,53,3,130,12,ES_AUTOHSCROLL + LTEXT "Nick:",IDC_STATIC,3,6,55,10 + EDITTEXT IDC_NICK,61,4,119,12,ES_AUTOHSCROLL + LTEXT "Default group:",IDC_STATIC,4,23,55,10 + EDITTEXT IDC_DEFGROUP,62,21,119,12,ES_AUTOHSCROLL CONTROL "Do not open chat windows on creation",IDC_HIDECHATS, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,0,21,182,10 + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,0,37,182,10 END IDD_OPTIONS DIALOGEX 0, 0, 305, 188 @@ -50,10 +52,12 @@ STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD EXSTYLE WS_EX_CONTROLPARENT FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN - LTEXT "Default group:",IDC_STATIC,5,8,79,10 - EDITTEXT IDC_DEFGROUP,87,7,211,12,ES_AUTOHSCROLL + LTEXT "Nick:",IDC_STATIC,5,6,79,10 + EDITTEXT IDC_NICK,87,5,211,12,ES_AUTOHSCROLL + LTEXT "Default group:",IDC_STATIC,5,24,79,10 + EDITTEXT IDC_DEFGROUP,87,23,211,12,ES_AUTOHSCROLL CONTROL "Do not open chat windows on creation",IDC_HIDECHATS, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,29,294,10 + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,43,294,10 END IDD_GROUPCHAT_INVITE DIALOGEX 0, 0, 215, 170 diff --git a/protocols/WhatsAppWeb/src/options.cpp b/protocols/WhatsAppWeb/src/options.cpp index 9270afd3d1..46b4d8da97 100644 --- a/protocols/WhatsAppWeb/src/options.cpp +++ b/protocols/WhatsAppWeb/src/options.cpp @@ -12,16 +12,18 @@ Copyright © 2019-22 George Hazan class COptionsDlg : public CProtoDlgBase<WhatsAppProto> { CCtrlCheck chkHideChats; - CCtrlEdit edtGroup; + CCtrlEdit edtGroup, edtNick; ptrW m_wszOldGroup; public: COptionsDlg(WhatsAppProto *ppro, int iDlgID, bool bFullDlg) : CProtoDlgBase<WhatsAppProto>(ppro, iDlgID), chkHideChats(this, IDC_HIDECHATS), + edtNick(this, IDC_NICK), edtGroup(this, IDC_DEFGROUP), m_wszOldGroup(mir_wstrdup(ppro->m_wszDefaultGroup)) { + CreateLink(edtNick, ppro->m_wszNick); CreateLink(edtGroup, ppro->m_wszDefaultGroup); if (bFullDlg) @@ -30,6 +32,11 @@ public: bool OnApply() override { + if (mir_wstrlen(m_proto->m_wszNick)) { + SetFocus(edtNick.GetHwnd()); + return false; + } + if (mir_wstrcmp(m_proto->m_wszDefaultGroup, m_wszOldGroup)) Clist_GroupCreate(0, m_proto->m_wszDefaultGroup); return true; diff --git a/protocols/WhatsAppWeb/src/proto.cpp b/protocols/WhatsAppWeb/src/proto.cpp index c29a7d60d9..1aa6117446 100644 --- a/protocols/WhatsAppWeb/src/proto.cpp +++ b/protocols/WhatsAppWeb/src/proto.cpp @@ -36,7 +36,9 @@ WhatsAppProto::WhatsAppProto(const char *proto_name, const wchar_t *username) : m_arOwnMsgs(1, CompareOwnMsgs), m_arPersistent(1), m_arPacketQueue(10), + m_wszNick(this, "Nick"), m_wszDefaultGroup(this, "DefaultGroup", L"WhatsApp"), + m_bUsePopups(this, "UsePopups", true), m_bHideGroupchats(this, "HideChats", true) { db_set_resident(m_szModuleName, "StatusMsg"); @@ -50,6 +52,7 @@ WhatsAppProto::WhatsAppProto(const char *proto_name, const wchar_t *username) : HookProtoEvent(ME_OPT_INITIALISE, &WhatsAppProto::OnOptionsInit); + InitPopups(); InitPersistentHandlers(); // Create standard network connection @@ -136,8 +139,12 @@ int WhatsAppProto::SetStatus(int new_status) if (m_iDesiredStatus == new_status) return 0; + if (!mir_wstrlen(m_wszNick)) { + Popup(0, LPGENW("You need to specify nick name in the Options dialog"), LPGENW("Error")); + return 0; + } + int oldStatus = m_iStatus; - debugLogA("===== Beginning SetStatus process"); // Routing statuses not supported by WhatsApp switch (new_status) { diff --git a/protocols/WhatsAppWeb/src/proto.h b/protocols/WhatsAppWeb/src/proto.h index 14ef70bd94..18f2eded6b 100644 --- a/protocols/WhatsAppWeb/src/proto.h +++ b/protocols/WhatsAppWeb/src/proto.h @@ -197,6 +197,14 @@ class WhatsAppProto : public PROTO<WhatsAppProto> void SendKeepAlive(); void SetServerStatus(int iStatus); + /// Popups ///////////////////////////////////////////////////////////////////////////// + + HANDLE m_hPopupClass; + CMOption<bool> m_bUsePopups; + + void InitPopups(void); + void Popup(MCONTACT hContact, const wchar_t *szMsg, const wchar_t *szTitle); + /// Request handlers /////////////////////////////////////////////////////////////////// void OnGetAvatarInfo(const JSONNode &node, void*); @@ -213,7 +221,7 @@ class WhatsAppProto : public PROTO<WhatsAppProto> void OnStreamError(const WANode &node); void OnSuccess(const WANode &node); - // binary packets + // Binary packets void ProcessBinaryPacket(const void *pData, size_t cbLen); /// Avatars //////////////////////////////////////////////////////////////////////////// @@ -263,6 +271,7 @@ public: // Options ///////////////////////////////////////////////////////////////////////////// + CMOption<wchar_t*> m_wszNick; // your nick name in presence CMOption<wchar_t*> m_wszDefaultGroup; // clist group to store contacts CMOption<bool> m_bHideGroupchats; // do not open chat windows on creation diff --git a/protocols/WhatsAppWeb/src/resource.h b/protocols/WhatsAppWeb/src/resource.h index 0326ab6d8f..c09b549e42 100644 --- a/protocols/WhatsAppWeb/src/resource.h +++ b/protocols/WhatsAppWeb/src/resource.h @@ -1,6 +1,6 @@ //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. -// Used by w:\miranda-ng\protocols\WhatsAppWeb\res\whatsapp.rc +// Used by W:\miranda-ng\protocols\WhatsAppWeb\res\whatsapp.rc // #define IDI_WHATSAPP 100 #define IDD_ACCMGRUI 101 @@ -9,8 +9,10 @@ #define IDC_HIDECHATS 1000 #define IDC_DEFGROUP 1001 #define IDC_QRPIC 1002 +#define IDC_DEFGROUP2 1002 #define IDC_CLIST 1003 #define IDC_NEWJID 1004 +#define IDC_NICK 1005 // Next default values for new objects // @@ -18,7 +20,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 104 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1005 +#define _APS_NEXT_CONTROL_VALUE 1006 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/protocols/WhatsAppWeb/src/server.cpp b/protocols/WhatsAppWeb/src/server.cpp index 1ac49b6037..9b534af176 100644 --- a/protocols/WhatsAppWeb/src/server.cpp +++ b/protocols/WhatsAppWeb/src/server.cpp @@ -273,12 +273,13 @@ void WhatsAppProto::SendKeepAlive() void WhatsAppProto::SetServerStatus(int iStatus) { - WANode iq("presence"); - iq << CHAR_PARAM("name", getMStringA("Nick")) << CHAR_PARAM("type", (iStatus == ID_STATUS_ONLINE) ? "available" : "unavailable"); - WSSendNode(iq); + if (mir_wstrlen(m_wszNick)) { + WANode iq("presence"); + iq << CHAR_PARAM("name", T2Utf(m_wszNick)) << CHAR_PARAM("type", (iStatus == ID_STATUS_ONLINE) ? "available" : "unavailable"); + WSSendNode(iq); + } } - ///////////////////////////////////////////////////////////////////////////////////////// void WhatsAppProto::ShutdownSession() diff --git a/protocols/WhatsAppWeb/src/utils.cpp b/protocols/WhatsAppWeb/src/utils.cpp index 01e299aca3..127ec33a45 100644 --- a/protocols/WhatsAppWeb/src/utils.cpp +++ b/protocols/WhatsAppWeb/src/utils.cpp @@ -293,3 +293,51 @@ unsigned char* HKDF(const EVP_MD *evp_md, return ret; } + +///////////////////////////////////////////////////////////////////////////////////////// +// Popups + +void WhatsAppProto::InitPopups(void) +{ + g_plugin.addPopupOption(CMStringW(FORMAT, TranslateT("%s error notifications"), m_tszUserName), m_bUsePopups); + + char name[256]; + mir_snprintf(name, "%s_%s", m_szModuleName, "Error"); + + wchar_t desc[256]; + mir_snwprintf(desc, L"%s/%s", m_tszUserName, TranslateT("Errors")); + + POPUPCLASS ppc = {}; + ppc.flags = PCF_UNICODE; + ppc.pszName = name; + ppc.pszDescription.w = desc; + ppc.hIcon = IcoLib_GetIconByHandle(m_hProtoIcon); + ppc.colorBack = RGB(191, 0, 0); //Red + ppc.colorText = RGB(255, 245, 225); //Yellow + ppc.iSeconds = 60; + m_hPopupClass = Popup_RegisterClass(&ppc); + + IcoLib_ReleaseIcon(ppc.hIcon); +} + +void WhatsAppProto::Popup(MCONTACT hContact, const wchar_t *szMsg, const wchar_t *szTitle) +{ + if (!m_bUsePopups) + return; + + char name[256]; + mir_snprintf(name, "%s_%s", m_szModuleName, "Error"); + + CMStringW wszTitle(szTitle); + if (hContact == 0) { + wszTitle.Insert(0, L": "); + wszTitle.Insert(0, m_tszUserName); + } + + POPUPDATACLASS ppd = {}; + ppd.szTitle.w = wszTitle; + ppd.szText.w = szMsg; + ppd.pszClassName = name; + ppd.hContact = hContact; + Popup_AddClass(&ppd); +} |