1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
#include "stdafx.h"
#define szAskSendSms LPGEN("An SMS with registration code will be sent to your mobile phone.\nNotice that you are not able to use the real WhatsApp and this plugin simultaneously!\nContinue?")
#define szAskCall LPGEN("A call with registration code will be made to your mobile phone.\nNotice that you are not able to use the real WhatsApp and this plugin simultaneously!\nContinue?")
#define szPasswordSet LPGEN("Your password has been set automatically. You can proceed with login now.")
#define szSpecifyCode LPGEN("Please correctly specify your registration code received by SMS/Voice.")
class COptionsDlg : public CProtoDlgBase<WhatsAppProto>
{
CCtrlEdit m_pw1, m_pw2, m_cc, m_login, m_nick, m_group;
CCtrlCheck m_ssl, m_autorun, m_remoteTime;
CCtrlButton m_requestSMS, m_requestVoice, m_register;
public:
COptionsDlg(WhatsAppProto *pThis, int dlgId) :
CProtoDlgBase<WhatsAppProto>(pThis, dlgId, false),
m_cc(this, IDC_CC),
m_pw1(this, IDC_PW),
m_pw2(this, IDC_PW2),
m_ssl(this, IDC_SSL),
m_remoteTime(this, IDC_REMOTE_TIME),
m_nick(this, IDC_NICK),
m_group(this, IDC_DEFGROUP),
m_login(this, IDC_LOGIN),
m_autorun(this, IDC_AUTORUN),
m_requestSMS(this, IDC_BUTTON_REQUEST_SMS_CODE),
m_requestVoice(this, IDC_BUTTON_REQUEST_VOICE_CODE),
m_register(this, IDC_BUTTON_REGISTER)
{
CreateLink(m_ssl, WHATSAPP_KEY_SSL, DBVT_BYTE, false);
CreateLink(m_remoteTime, WHATSAPP_KEY_USE_REMOTE_TIME, DBVT_BYTE, false);
CreateLink(m_autorun, WHATSAPP_KEY_AUTORUNCHATS, DBVT_BYTE, true);
CreateLink(m_cc, WHATSAPP_KEY_CC, L"");
CreateLink(m_nick, WHATSAPP_KEY_NICK, L"");
CreateLink(m_login, WHATSAPP_KEY_LOGIN, L"");
CreateLink(m_group, WHATSAPP_KEY_DEF_GROUP, L"");
m_requestSMS.OnClick = Callback(this, &COptionsDlg::OnRequestSMSClick);
m_requestVoice.OnClick = Callback(this, &COptionsDlg::OnRequestVoiceClick);
m_register.OnClick = Callback(this, &COptionsDlg::OnRegisterClick);
}
virtual void OnInitDialog()
{
m_pw1.SendMsg(EM_LIMITTEXT, 3, 0);
m_pw2.SendMsg(EM_LIMITTEXT, 3, 0);
bool bEnable = m_proto->getBool("CodeRequestDone", false);
m_pw1.Enable(bEnable);
m_pw2.Enable(bEnable);
}
void OnRequestVoiceClick(CCtrlButton*)
{
if (IDYES != MessageBox(GetHwnd(), TranslateT(szAskCall), PRODUCT_NAME, MB_YESNO))
return;
ptrA cc(m_cc.GetTextA()), number(m_login.GetTextA());
string password;
if (m_proto->Register(REG_STATE_REQ_CODE, string(cc), string(number), "voice", password)) {
if (!password.empty()) {
MessageBox(GetHwnd(), TranslateT(szPasswordSet), PRODUCT_NAME, MB_ICONWARNING);
m_proto->setString(WHATSAPP_KEY_PASS, password.c_str());
}
else {
// unblock sms code entry field
m_pw1.Enable();
m_pw2.Enable();
m_proto->setByte("CodeRequestDone", 1);
}
}
}
void OnRequestSMSClick(CCtrlButton*)
{
if (IDYES != MessageBox(GetHwnd(), TranslateT(szAskSendSms), PRODUCT_NAME, MB_YESNO))
return;
ptrA cc(m_cc.GetTextA()), number(m_login.GetTextA());
string password;
if (m_proto->Register(REG_STATE_REQ_CODE, string(cc), string(number), "sms", password)) {
if (!password.empty()) {
MessageBox(GetHwnd(), TranslateT(szPasswordSet), PRODUCT_NAME, MB_ICONWARNING);
m_proto->setString(WHATSAPP_KEY_PASS, password.c_str());
}
else {
// unblock sms code entry field
m_pw1.Enable();
m_pw2.Enable();
m_proto->setByte("CodeRequestDone", 1);
}
}
}
void OnRegisterClick(CCtrlButton*)
{
if (GetWindowTextLength(m_pw1.GetHwnd()) != 3 || GetWindowTextLength(m_pw2.GetHwnd()) != 3)
MessageBox(GetHwnd(), TranslateT(szSpecifyCode), PRODUCT_NAME, MB_ICONEXCLAMATION);
else {
char code[10];
GetWindowTextA(m_pw1.GetHwnd(), code, 4);
GetWindowTextA(m_pw2.GetHwnd(), code + 3, 4);
string password;
ptrA cc(m_cc.GetTextA()), number(m_login.GetTextA());
if (m_proto->Register(REG_STATE_REG_CODE, string(cc), string(number), string(code), password)) {
m_proto->setString(WHATSAPP_KEY_PASS, password.c_str());
MessageBox(GetHwnd(), TranslateT(szPasswordSet), PRODUCT_NAME, MB_ICONWARNING);
}
}
m_proto->setByte("CodeRequestDone", 0);
}
virtual void OnApply()
{
ptrT tszGroup(m_group.GetText());
if (mir_tstrcmp(m_proto->m_tszDefaultGroup, tszGroup))
m_proto->m_tszDefaultGroup = tszGroup.detach();
if (m_proto->isOnline())
MessageBox(GetHwnd(), TranslateT("Changes will be applied after protocol restart"), m_proto->m_tszUserName, MB_OK);
}
};
INT_PTR WhatsAppProto::SvcCreateAccMgrUI(WPARAM, LPARAM lParam)
{
COptionsDlg *pDlg = new COptionsDlg(this, IDD_ACCMGRUI);
pDlg->SetParent((HWND)lParam);
pDlg->Show();
return (INT_PTR)pDlg->GetHwnd();
}
int WhatsAppProto::OnOptionsInit(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = { 0 };
odp.ptszTitle = m_tszUserName;
odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR | ODPF_DONTTRANSLATE;
odp.ptszGroup = LPGENT("Network");
odp.ptszTab = LPGENT("Account");
odp.pDialog = new COptionsDlg(this, IDD_OPTIONS);
Options_AddPage(wParam, &odp);
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
// Invite dialog
class CInviteDialog : public CProtoDlgBase<WhatsAppProto>
{
CCtrlClc m_clc;
CCtrlEdit m_entry;
CCtrlButton m_btnOk;
void FilterList(CCtrlClc *)
{
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
char *proto = GetContactProto(hContact);
if (mir_strcmp(proto, m_proto->m_szModuleName) || m_proto->isChatRoom(hContact))
if (HANDLE hItem = m_clc.FindContact(hContact))
m_clc.DeleteItem(hItem);
}
}
void ResetListOptions(CCtrlClc *)
{
m_clc.SetBkBitmap(0, NULL);
m_clc.SetBkColor(GetSysColor(COLOR_WINDOW));
m_clc.SetGreyoutFlags(0);
m_clc.SetLeftMargin(4);
m_clc.SetIndent(10);
m_clc.SetHideEmptyGroups(true);
m_clc.SetHideOfflineRoot(true);
for (int i = 0; i <= FONTID_MAX; i++)
m_clc.SetTextColor(i, GetSysColor(COLOR_WINDOWTEXT));
}
public:
CInviteDialog(WhatsAppProto *pThis) :
CProtoDlgBase<WhatsAppProto>(pThis, IDD_GROUPCHAT_INVITE, false),
m_clc(this, IDC_CLIST),
m_entry(this, IDC_NEWJID),
m_btnOk(this, IDOK)
{
m_btnOk.OnClick = Callback(this, &CInviteDialog::btnOk_OnClick);
m_clc.OnNewContact =
m_clc.OnListRebuilt = Callback(this, &CInviteDialog::FilterList);
m_clc.OnOptionsChanged = Callback(this, &CInviteDialog::ResetListOptions);
}
void OnInitDialog()
{
SetWindowLongPtr(m_clc.GetHwnd(), GWL_STYLE,
GetWindowLongPtr(m_clc.GetHwnd(), GWL_STYLE) | CLS_CHECKBOXES | CLS_HIDEEMPTYGROUPS | CLS_USEGROUPS | CLS_GREYALTERNATE);
m_clc.SendMsg(CLM_SETEXSTYLE, CLS_EX_DISABLEDRAGDROP | CLS_EX_TRACKSELECT, 0);
ResetListOptions(&m_clc);
FilterList(&m_clc);
}
void btnOk_OnClick(CCtrlButton*)
{
m_proto->m_szInviteJids.clear();
// invite users from clist
for (MCONTACT hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) {
if (m_proto->isChatRoom(hContact))
continue;
if (HANDLE hItem = m_clc.FindContact(hContact)) {
if (m_clc.GetCheck(hItem)) {
ptrA jid(m_proto->getStringA(hContact, "ID"));
if (jid != NULL)
m_proto->m_szInviteJids.push_back((char*)jid);
}
}
}
ptrA tszText(m_entry.GetTextA());
if (tszText != NULL)
m_proto->m_szInviteJids.push_back(string(tszText));
}
};
void WhatsAppProto::InviteChatUser(WAChatInfo *pInfo)
{
CInviteDialog dlg(this);
if (!dlg.DoModal())
return;
if (isOnline()) {
m_pConnection->sendAddParticipants((char*)_T2A(pInfo->tszJid), m_szInviteJids);
m_szInviteJids.clear();
}
}
|