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
236
237
238
239
240
241
242
243
244
245
246
247
|
/*
Miranda NG: the free IM client for Microsoft* Windows*
Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org),
Copyright (c) 2000-12 Miranda IM project,
all portions of this codebase are copyrighted to the people
listed in contributors.txt.
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; either version 2
of the License, or (at your option) any later version.
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, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "..\..\core\commonheaders.h"
class CAddContactDlg : public CDlgBase
{
ADDCONTACTSTRUCT m_acs;
CCtrlEdit m_authReq, m_myHandle;
CCtrlCheck m_chkAdded, m_chkAuth, m_chkOpen;
CCtrlButton m_btnOk;
CCtrlCombo m_group;
public:
CAddContactDlg(ADDCONTACTSTRUCT *acs) :
CDlgBase(hInst, IDD_ADDCONTACT),
m_chkAdded(this, IDC_ADDED),
m_chkAuth(this, IDC_AUTH),
m_chkOpen(this, IDC_OPEN_WINDOW),
m_btnOk(this, IDOK),
m_group(this, IDC_GROUP),
m_authReq(this, IDC_AUTHREQ),
m_myHandle(this, IDC_MYHANDLE)
{
m_chkAuth.OnChange = Callback(this, &CAddContactDlg::OnAuthClicked);
m_chkOpen.OnChange = Callback(this, &CAddContactDlg::OnOpenClicked);
m_btnOk.OnClick = Callback(this, &CAddContactDlg::OnOk);
m_acs = *acs;
if (m_acs.psr) {
PROTOSEARCHRESULT *psr = (PROTOSEARCHRESULT*)mir_alloc(m_acs.psr->cbSize);
memcpy(psr, m_acs.psr, m_acs.psr->cbSize);
psr->nick.t = (psr->flags & PSR_UNICODE) ? mir_u2t((wchar_t*)psr->nick.t) : mir_a2t((char*)psr->nick.t);
psr->firstName.t = (psr->flags & PSR_UNICODE) ? mir_u2t((wchar_t*)psr->firstName.t) : mir_a2t((char*)psr->firstName.t);
psr->lastName.t = (psr->flags & PSR_UNICODE) ? mir_u2t((wchar_t*)psr->lastName.t) : mir_a2t((char*)psr->lastName.t);
psr->email.t = (psr->flags & PSR_UNICODE) ? mir_u2t((wchar_t*)psr->email.t) : mir_a2t((char*)psr->email.t);
psr->id.t = (psr->flags & PSR_UNICODE) ? mir_u2t((wchar_t*)psr->id.t) : mir_a2t((char*)psr->id.t);
psr->flags = psr->flags & ~PSR_UNICODE | PSR_TCHAR;
m_acs.psr = psr;
}
}
void OnInitDialog()
{
char szUin[10];
Window_SetIcon_IcoLib(m_hwnd, SKINICON_OTHER_ADDCONTACT);
if (m_acs.handleType == HANDLE_EVENT) {
DWORD dwUin;
DBEVENTINFO dbei = { sizeof(dbei) };
dbei.cbBlob = sizeof(DWORD);
dbei.pBlob = (PBYTE)&dwUin;
db_event_get(m_acs.hDbEvent, &dbei);
_ltoa(dwUin, szUin, 10);
m_acs.szProto = dbei.szModule;
}
MCONTACT hContact;
TCHAR *szName = NULL, *tmpStr = NULL;
if (m_acs.handleType == HANDLE_CONTACT)
szName = cli.pfnGetContactDisplayName(hContact = m_acs.hContact, 0);
else {
int isSet = 0;
hContact = 0;
if (m_acs.handleType == HANDLE_EVENT) {
DBEVENTINFO dbei = { sizeof(dbei) };
dbei.cbBlob = db_event_getBlobSize(m_acs.hDbEvent);
dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob);
db_event_get(m_acs.hDbEvent, &dbei);
hContact = *(MCONTACT*)(dbei.pBlob + sizeof(DWORD));
mir_free(dbei.pBlob);
if (hContact != INVALID_CONTACT_ID) {
szName = cli.pfnGetContactDisplayName(hContact, 0);
isSet = 1;
}
}
if (!isSet) {
szName = (m_acs.handleType == HANDLE_EVENT) ? (tmpStr = mir_a2t(szUin)) :
(m_acs.psr->id.t ? m_acs.psr->id.t : m_acs.psr->nick.t);
}
}
if (szName && szName[0])
SetCaption(CMString(FORMAT, TranslateT("Add %s"), szName));
else
SetCaption(TranslateT("Add contact"));
mir_free(tmpStr);
if (m_acs.handleType == HANDLE_CONTACT && m_acs.hContact)
if (m_acs.szProto == NULL || (m_acs.szProto != NULL && *m_acs.szProto == 0))
m_acs.szProto = GetContactProto(m_acs.hContact);
int groupSel = 0;
ptrT tszGroup(db_get_tsa(hContact, "CList", "Group"));
TCHAR *grpName;
for (int groupId = 1; (grpName = cli.pfnGetGroupName(groupId, NULL)) != NULL; groupId++) {
int id = m_group.AddString(grpName, groupId);
if (!mir_tstrcmpi(tszGroup, grpName))
groupSel = id;
}
m_group.InsertString(TranslateT("None"), 0);
m_group.SetCurSel(groupSel);
// By default check both checkboxes
m_chkAdded.SetState(true);
m_chkAuth.SetState(true);
// Set last choice
if (db_get_b(NULL, "Miranda", "AuthOpenWindow", 1))
m_chkOpen.SetState(true);
DWORD flags = (m_acs.szProto) ? CallProtoServiceInt(NULL, m_acs.szProto, PS_GETCAPS, PFLAGNUM_4, 0) : 0;
if (flags & PF4_FORCEADDED) // force you were added requests for this protocol
m_chkAdded.Enable(false);
if (flags & PF4_FORCEAUTH) // force auth requests for this protocol
m_chkAuth.Enable(false);
if (flags & PF4_NOCUSTOMAUTH)
m_authReq.Enable(false);
else {
m_authReq.Enable(m_chkAuth.Enabled());
m_authReq.SetText(TranslateT("Please authorize my request and add me to your contact list."));
}
}
void OnDestroy()
{
Window_FreeIcon_IcoLib(m_hwnd);
if (m_acs.psr) {
mir_free(m_acs.psr->nick.t);
mir_free(m_acs.psr->firstName.t);
mir_free(m_acs.psr->lastName.t);
mir_free(m_acs.psr->email.t);
mir_free(m_acs.psr);
}
}
void OnAuthClicked(CCtrlButton*)
{
DWORD flags = CallProtoServiceInt(NULL, m_acs.szProto, PS_GETCAPS, PFLAGNUM_4, 0);
if (flags & PF4_NOCUSTOMAUTH)
m_authReq.Enable(false);
else
m_authReq.Enable(m_chkAuth.Enabled());
}
void OnOpenClicked(CCtrlButton*)
{
// Remember this choice
db_set_b(NULL, "Miranda", "AuthOpenWindow", m_chkOpen.Enabled());
}
void OnOk(CCtrlButton*)
{
MCONTACT hContact = INVALID_CONTACT_ID;
switch (m_acs.handleType) {
case HANDLE_EVENT:
{
DBEVENTINFO dbei = { sizeof(dbei) };
db_event_get(m_acs.hDbEvent, &dbei);
hContact = (MCONTACT)CallProtoServiceInt(NULL, dbei.szModule, PS_ADDTOLISTBYEVENT, 0, (LPARAM)m_acs.hDbEvent);
}
break;
case HANDLE_SEARCHRESULT:
hContact = (MCONTACT)CallProtoServiceInt(NULL, m_acs.szProto, PS_ADDTOLIST, 0, (LPARAM)m_acs.psr);
break;
case HANDLE_CONTACT:
hContact = m_acs.hContact;
break;
}
if (hContact == NULL)
return;
ptrT szHandle(m_myHandle.GetText());
if (mir_tstrlen(szHandle))
db_set_ts(hContact, "CList", "MyHandle", szHandle);
int item = m_group.GetCurSel();
if (item > 0)
CallService(MS_CLIST_CONTACTCHANGEGROUP, hContact, m_group.GetItemData(item));
db_unset(hContact, "CList", "NotOnList");
if (m_chkAdded.GetState())
CallContactService(hContact, PSS_ADDED, 0, 0);
if (m_chkAuth.GetState()) {
DWORD flags = CallProtoServiceInt(NULL, m_acs.szProto, PS_GETCAPS, PFLAGNUM_4, 0);
if (flags & PF4_NOCUSTOMAUTH)
CallContactService(hContact, PSS_AUTHREQUEST, 0, 0);
else
CallContactService(hContact, PSS_AUTHREQUEST, 0, ptrT(m_authReq.GetText()));
}
if (m_chkOpen.GetState())
CallService(MS_CLIST_CONTACTDOUBLECLICKED, hContact, 0);
}
};
INT_PTR AddContactDialog(WPARAM wParam, LPARAM lParam)
{
if (lParam == 0)
return 1;
ADDCONTACTSTRUCT *acs = (ADDCONTACTSTRUCT*)lParam;
if (wParam) {
CAddContactDlg dlg(acs);
dlg.SetParent((HWND)wParam);
dlg.DoModal();
}
else (new CAddContactDlg(acs))->Show();
return 0;
}
int LoadAddContactModule(void)
{
CreateServiceFunction(MS_ADDCONTACT_SHOW, AddContactDialog);
return 0;
}
|