summaryrefslogtreecommitdiff
path: root/plugins/Dropbox/src/dropbox_menus.cpp
blob: 0dcac861a86bf01a2187f081bf7fb385e33d07b4 (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
#include "common.h"

void CDropbox::InitMenus()
{
	CLISTMENUITEM mi = { 0 };
	mi.cbSize = sizeof(CLISTMENUITEM);
	mi.flags = CMIF_TCHAR;

	mi.pszService = MODULE"/SendFilesToDropbox";
	mi.ptszName = LPGENT("Send files to Dropbox");
	mi.position = -2000020000 + CMI_SEND_FILES;
	mi.icolibItem = LoadSkinnedIconHandle(SKINICON_EVENT_FILE);
	ContactMenuItems[CMI_SEND_FILES] = Menu_AddContactMenuItem(&mi);
	CreateServiceFunction(mi.pszService, SendFilesToDropbox);

	mi.pszService = MODULE"/RequestAuthorization";
	mi.ptszName = LPGENT("Request authorization");
	mi.position = 1000030000 + CMI_AUTH_REQUEST;
	mi.icolibItem = LoadSkinnedIconHandle(SKINICON_AUTH_REQUEST);
	ContactMenuItems[CMI_AUTH_REQUEST] = Menu_AddContactMenuItem(&mi);
	CreateServiceFunction(mi.pszService, RequestApiAuthorization);

	mi.pszService = MODULE"/RevokeAuthorization";
	mi.ptszName = LPGENT("Revoke authorization");
	mi.position = 1000030000 + CMI_AUTH_REVOKE;
	mi.icolibItem = LoadSkinnedIconHandle(SKINICON_AUTH_REVOKE);
	ContactMenuItems[CMI_AUTH_REVOKE] = Menu_AddContactMenuItem(&mi);
	CreateServiceFunction(mi.pszService, RevokeApiAuthorization);
}

void CDropbox::Menu_DisableItem(HGENMENU hMenuItem, BOOL bDisable)
{
	CLISTMENUITEM clmi = { sizeof(clmi) };
	clmi.cbSize = sizeof(CLISTMENUITEM);
	clmi.flags = CMIM_FLAGS;
	if (bDisable)
		clmi.flags |= CMIF_GRAYED;

	Menu_ModifyItem(hMenuItem, &clmi);
}

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

	Menu_DisableItem(ContactMenuItems[CMI_SEND_FILES], FALSE);

	Menu_ShowItem(ContactMenuItems[CMI_AUTH_REQUEST], FALSE);
	Menu_ShowItem(ContactMenuItems[CMI_AUTH_REVOKE], FALSE);
	Menu_ShowItem(ContactMenuItems[CMI_SEND_FILES], FALSE);

	WORD status = db_get_w(hContact, GetContactProto(hContact), "Status", ID_STATUS_OFFLINE);

	if (hContact == GetDefaultContact())
	{
		if (!HasAccessToken())
			Menu_ShowItem(ContactMenuItems[CMI_AUTH_REQUEST], TRUE);
		else
			Menu_ShowItem(ContactMenuItems[CMI_AUTH_REVOKE], TRUE);
	}
	else if (status != ID_STATUS_OFFLINE && HasAccessToken())
		Menu_ShowItem(ContactMenuItems[CMI_SEND_FILES], TRUE);

	if (INSTANCE->hContactTransfer)
		Menu_DisableItem(ContactMenuItems[CMI_SEND_FILES], TRUE);

	return 0;
}