summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_menus.cpp
blob: 88d7129713c090e0eeb5418a6a8d772689c361f8 (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
#include "stdafx.h"

HGENMENU CToxProto::ContactMenuItems[CMI_MAX];

int CToxProto::OnPrebuildContactMenu(WPARAM hContact, LPARAM)
{
	if (!hContact)
		return 0;

	if (!this->IsOnline())
		return 0;

	if (this->isChatRoom(hContact))
		return 0;

	bool isCtrlPressed = (GetKeyState(VK_CONTROL) & 0x8000) != 0;

	bool isAuthNeed = getByte(hContact, "Auth", 0) > 0;
	Menu_ShowItem(ContactMenuItems[CMI_AUTH_REQUEST], isCtrlPressed || isAuthNeed);

	bool isGrantNeed = getByte(hContact, "Grant", 0) > 0;
	Menu_ShowItem(ContactMenuItems[CMI_AUTH_GRANT], isCtrlPressed || isGrantNeed);

	return 0;
}

int CToxProto::PrebuildContactMenu(WPARAM hContact, LPARAM lParam)
{
	for (int i = 0; i < _countof(ContactMenuItems); i++)
		Menu_ShowItem(ContactMenuItems[i], FALSE);
	CToxProto *proto = CToxProto::GetContactAccount(hContact);
	return proto ? proto->OnPrebuildContactMenu(hContact, lParam) : 0;
}

void CToxProto::InitContactMenu()
{
	HookEvent(ME_CLIST_PREBUILDCONTACTMENU, &CToxProto::PrebuildContactMenu);

	CMenuItem mi;
	mi.flags = CMIF_UNICODE;

	// Request authorization
	SET_UID(mi, 0x36375a1f, 0xc142, 0x4d6e, 0xa6, 0x57, 0xe4, 0x76, 0x5d, 0xbc, 0x59, 0x8e);
	mi.pszService = MODULE"/RequestAuth";
	mi.name.w = LPGENW("Request authorization");
	mi.position = CMI_POSITION + CMI_AUTH_REQUEST;
	mi.hIcolibItem = ::Skin_GetIconHandle(SKINICON_AUTH_REQUEST);
	ContactMenuItems[CMI_AUTH_REQUEST] = Menu_AddContactMenuItem(&mi);
	CreateServiceFunction(mi.pszService, GlobalService<&CToxProto::OnRequestAuth>);

	// Grant authorization
	SET_UID(mi, 0x4c90452a, 0x869a, 0x4a81, 0xaf, 0xa8, 0x28, 0x34, 0xaf, 0x2b, 0x6b, 0x30);
	mi.pszService = MODULE"/GrantAuth";
	mi.name.w = LPGENW("Grant authorization");
	mi.position = CMI_POSITION + CMI_AUTH_GRANT;
	mi.hIcolibItem = ::Skin_GetIconHandle(SKINICON_AUTH_GRANT);
	ContactMenuItems[CMI_AUTH_GRANT] = Menu_AddContactMenuItem(&mi);
	CreateServiceFunction(mi.pszService, GlobalService<&CToxProto::OnGrantAuth>);
}

int CToxProto::UpdateStatusMenu(WPARAM, LPARAM)
{
	bool isOnline = IsOnline();
	Menu_EnableItem(StatusMenuItems[SMI_PASSWORD], isOnline);
	Menu_EnableItem(StatusMenuItems[SMI_PASSWORD_CREATE], isOnline);
	Menu_EnableItem(StatusMenuItems[SMI_PASSWORD_CHANGE], isOnline);
	Menu_EnableItem(StatusMenuItems[SMI_PASSWORD_REMOVE], isOnline);

	pass_ptrW password(getWStringA(TOX_SETTINGS_PASSWORD));
	bool passwordExists = mir_wstrlen(password) > 0;
	Menu_ShowItem(StatusMenuItems[SMI_PASSWORD_CREATE], !passwordExists);
	Menu_ShowItem(StatusMenuItems[SMI_PASSWORD_CHANGE], passwordExists);
	Menu_ShowItem(StatusMenuItems[SMI_PASSWORD_REMOVE], passwordExists);

	return 0;
}

int CToxProto::OnInitStatusMenu()
{
	//HookProtoEvent(ME_CLIST_PREBUILDSTATUSMENU, &CToxProto::UpdateStatusMenu);

	CMenuItem mi;
	mi.flags = CMIF_UNICODE;
	mi.root = Menu_GetProtocolRoot(this);

	// Create copy tox id command
	mi.pszService = "/CopyToxID";
	CreateProtoService(mi.pszService, &CToxProto::OnCopyToxID);
	mi.name.w = LPGENW("Copy Tox ID");
	mi.position = SMI_POSITION + SMI_TOXID_COPY;
	StatusMenuItems[SMI_TOXID_COPY] = Menu_AddProtoMenuItem(&mi, m_szModuleName);

	// Password
	mi.pszService = nullptr;
	mi.name.w = LPGENW("Password");
	StatusMenuItems[SMI_PASSWORD] = Menu_AddProtoMenuItem(&mi, m_szModuleName);
	mi.root = StatusMenuItems[SMI_PASSWORD];

	// Create password command
	mi.pszService = "/CreatePassword";
	CreateProtoService(mi.pszService, &CToxProto::OnCreatePassword);
	mi.name.w = LPGENW("Create password");
	mi.position = SMI_PASSWORD_CREATE;
	StatusMenuItems[SMI_PASSWORD_CREATE] = Menu_AddProtoMenuItem(&mi, m_szModuleName);

	// Change password command
	mi.pszService = "/ChangePassword";
	CreateProtoService(mi.pszService, &CToxProto::OnChangePassword);
	mi.name.w = LPGENW("Change password");
	mi.position = SMI_PASSWORD_CHANGE;
	StatusMenuItems[SMI_PASSWORD_CHANGE] = Menu_AddProtoMenuItem(&mi, m_szModuleName);

	// Remove password command
	mi.pszService = "/RemovePassword";
	CreateProtoService(mi.pszService, &CToxProto::OnRemovePassword);
	mi.name.w = LPGENW("Remove password");
	mi.position = SMI_PASSWORD_REMOVE;
	StatusMenuItems[SMI_PASSWORD_REMOVE] = Menu_AddProtoMenuItem(&mi, m_szModuleName);

	UpdateStatusMenu(NULL, NULL);

	return 0;
}