summaryrefslogtreecommitdiff
path: root/protocols/Telegram/src/userinfo.cpp
blob: 30b3af0050e6d859025caa1d7a45a6f2676edb1f (plain)
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
/*
Copyright (C) 2012-25 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"

/////////////////////////////////////////////////////////////////////////////////////////
// Dialog for my own profile in Telegram

class CMyProfileDlg : public CUserInfoPageDlg
{
	CTelegramProto *m_proto;
	CCtrlEdit edtNotes;

public:
	CMyProfileDlg(CTelegramProto *ppro) :
		CUserInfoPageDlg(g_plugin, IDD_MYPROFILE),
		m_proto(ppro),
		edtNotes(this, IDC_BIO)
	{}

	bool OnRefresh() override
	{
		HWND _hwndDate = GetDlgItem(m_hwnd, IDC_BIRTHDAY);
		SYSTEMTIME st = {};
		st.wDay = m_proto->getWord(m_hContact, "BirthDay");
		st.wMonth = m_proto->getWord(m_hContact, "BirthMonth");
		st.wYear = m_proto->getWord(m_hContact, "BirthYear");

		if (st.wDay && st.wMonth && st.wYear) {
			DateTime_SetSystemtime(_hwndDate, GDT_VALID, &st);
			DateTime_SetFormat(_hwndDate, NULL);
		}
		else DateTime_SetFormat(_hwndDate, TranslateT("Unspecified"));

		edtNotes.SetText(m_proto->getMStringW(m_hContact, "About"));
		return true;
	}

	bool OnInitDialog() override
	{
		m_proto->WindowSubscribe(m_hwnd);

		m_proto->GetInfo(0, 0);
		return true;
	}

	int Resizer(UTILRESIZECONTROL *urc) override
	{
		switch (urc->wId) {
		case IDC_BIO:
			return RD_ANCHORX_WIDTH | RD_ANCHORY_HEIGHT;
		}
		return RD_ANCHORX_LEFT | RD_ANCHORY_TOP;
	}

	void OnDestroy() override
	{
		m_proto->WindowUnsubscribe(m_hwnd);
	}
};

/////////////////////////////////////////////////////////////////////////////////////////
// Channel info dialog

class CChannelInfoDlg : public CUserInfoPageDlg
{
	CMStringA m_szLink;
	CTelegramProto *m_proto;

	CCtrlEdit edtUserCount;
	CCtrlHyperlink m_link;

public:
	CChannelInfoDlg(CTelegramProto *ppro) :
		CUserInfoPageDlg(g_plugin, IDD_CHANNEL_INFO),
		m_proto(ppro),
		m_link(this, IDC_LINK),
		edtUserCount(this, IDC_USER_COUNT)
	{}

	bool OnInitDialog() override
	{
		m_proto->WindowSubscribe(m_hwnd);
		return true;
	}

	int Resizer(UTILRESIZECONTROL *urc) override
	{
		switch (urc->wId) {
		case IDC_LINK:
			return RD_ANCHORX_WIDTH | RD_ANCHORY_TOP;
		}
		return RD_ANCHORX_RIGHT | RD_ANCHORY_TOP;
	}

	void OnDestroy() override
	{
		m_proto->WindowUnsubscribe(m_hwnd);
	}

	bool OnRefresh() override
	{
		edtUserCount.SetInt(m_proto->getDword(m_hContact, "MemberCount"));

		m_szLink = m_proto->getMStringA(m_hContact, "Link");
		m_link.SetUrl(m_szLink);
		m_link.SetTextA(m_szLink);
		return true;
	}
};

/////////////////////////////////////////////////////////////////////////////////////////
// module entry point

int CTelegramProto::OnUserInfoInit(WPARAM wParam, LPARAM hContact)
{
	USERINFOPAGE uip = {};
	uip.flags = ODPF_UNICODE | ODPF_ICON;
	uip.szProto = m_szModuleName;
	uip.szTitle.w = m_tszUserName;
	uip.dwInitParam = (INT_PTR)Skin_GetProtoIcon(m_szModuleName, ID_STATUS_ONLINE);

	if (hContact != 0) {
		// we display this tab only for our contacts
		char *szProto = Proto_GetBaseAccountName(hContact);
		if (!szProto || mir_strcmp(szProto, m_szModuleName))
			return 0;

		auto *pUser = FindUser(GetId(hContact));
		if (pUser && pUser->isChannel)
			uip.pDialog = new CChannelInfoDlg(this);
		else
			return 0;
	}
	else uip.pDialog = new CMyProfileDlg(this);
	return g_plugin.addUserInfo(wParam, &uip);
}