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
|
/*
Copyright (C) 2012-24 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"
class CAddPhoneContactDlg : public CTelegramDlgBase
{
CCtrlEdit edtFirstName, edtLastName, edtPhone;
CCtrlCombo cmbCountry;
CCtrlButton btnOk;
public:
CAddPhoneContactDlg(CTelegramProto *ppro) :
CTelegramDlgBase(ppro, IDD_ADD_PHONE),
btnOk(this, IDOK),
edtPhone(this, IDC_PHONE),
cmbCountry(this, IDC_COUNTRY),
edtLastName(this, IDC_LAST_NAME),
edtFirstName(this, IDC_FIRST_NAME)
{
cmbCountry.OnChange = Callback(this, &CAddPhoneContactDlg::onChange_Country);
}
bool OnInitDialog() override
{
int iCount;
CountryListEntry *pList;
CallService(MS_UTILS_GETCOUNTRYLIST, (WPARAM)&iCount, (LPARAM)&pList);
for (int i = 0; i < iCount; i++) {
unsigned countryCode = pList[i].id;
int idx = cmbCountry.AddString(TranslateW(_A2T(pList[i].szName).get()), countryCode);
if (countryCode == m_proto->m_iCountry)
cmbCountry.SetCurSel(idx);
}
onChange_Country(0);
return true;
}
bool OnApply() override
{
CMStringW wszCountry(FORMAT, L"+%d%s", (int)cmbCountry.GetCurData(), ptrW(edtPhone.GetText()).get());
auto *cc = new TD::contact;
cc->first_name_ = T2Utf(ptrW(edtFirstName.GetText()));
cc->last_name_ = T2Utf(ptrW(edtLastName.GetText()));
cc->phone_number_ = T2Utf(wszCountry);
TD::array<TD::object_ptr<TD::contact>> contacts;
contacts.push_back(TD::object_ptr<TD::contact>(cc));
m_proto->SendQuery(new TD::importContacts(std::move(contacts)));
return true;
}
void OnChange() override
{
ptrW wszFirstName(edtFirstName.GetText()), wszPhone(edtPhone.GetText());
btnOk.Enable(mir_wstrlen(wszFirstName) && mir_wstrlen(wszPhone) && cmbCountry.GetCurData() != 9999);
}
void onChange_Country(CCtrlCombo *)
{
CMStringA buf;
switch (int iCode = cmbCountry.GetCurData()) {
case 9999:
case -1:
buf = "---";
break;
default:
buf.Format("+%d", iCode);
}
SetDlgItemTextA(m_hwnd, IDC_CODE, buf);
}
};
INT_PTR CTelegramProto::SvcAddByPhone(WPARAM, LPARAM)
{
(new CAddPhoneContactDlg(this))->Show();
return 0;
}
|