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

int CDropbox::OnModulesLoaded(WPARAM wParam, LPARAM lParam)
{
	HookEvent(ME_FILEDLG_CANCELED, CDropbox::OnFileDoalogCancelled);
	HookEvent(ME_FILEDLG_SUCCEEDED, CDropbox::OnFileDoalogSuccessed);

	NETLIBUSER nlu = { sizeof(nlu) };
	nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR;
	nlu.szSettingsModule = MODULE;
	nlu.szSettingsModule = MODULE;
	nlu.ptszDescriptiveName = L"Dropbox";

	INSTANCE->hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);

	MCONTACT hContact = GetDefaultContact();
	if (!hContact)
	{
		hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
		if (!CallService(MS_PROTO_ADDTOCONTACT, hContact, (LPARAM)MODULE))
		{
			db_set_s(NULL, MODULE, "Nick", MODULE);
			db_set_s(hContact, MODULE, "Nick", MODULE);
			db_set_ws(hContact, "CList", "MyHandle", L"Dropbox");

			if (HasAccessToken() && db_get_w(hContact, MODULE, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE)
			{
				db_set_w(hContact, MODULE, "Status", ID_STATUS_ONLINE);
			}
		}
	}

	if (ServiceExists(MS_BB_ADDBUTTON))
	{
		BBButton bbd = { sizeof(bbd) };
		bbd.pszModuleName = MODULE;

		bbd.bbbFlags = BBBF_ISIMBUTTON | BBBF_ISRSIDEBUTTON;
		bbd.ptszTooltip = TranslateT("Send files to Dropbox");
		bbd.hIcon = LoadSkinnedIconHandle(SKINICON_EVENT_FILE);
		bbd.dwButtonID = BBB_ID_FILE_SEND;
		bbd.dwDefPos = 100 + bbd.dwButtonID;
		CallService(MS_BB_ADDBUTTON, 0, (LPARAM)&bbd);

		HookEvent(ME_MSG_WINDOWEVENT, CDropbox::OnSrmmWindowOpened);
		HookEvent(ME_MSG_BUTTONPRESSED, CDropbox::OnSrmmButtonPressed);
	}

	return 0;
}

int CDropbox::OnOptionsInit(WPARAM wParam, LPARAM lParam)
{
	OPTIONSDIALOGPAGE odp = { sizeof(odp) };
	odp.position = 100000000;
	odp.hInstance = g_hInstance;
	odp.flags = ODPF_BOLDGROUPS;
	odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS_MAIN);
	odp.pszGroup = LPGEN("Network");
	odp.pszTitle = LPGEN("Dropbox");
	odp.pfnDlgProc = MainOptionsProc;

	//Options_AddPage(wParam, &odp);

	return 0;
}

int CDropbox::OnContactDeleted(WPARAM hContact, LPARAM lParam)
{
	if (lstrcmpiA(GetContactProto(hContact), MODULE) == 0)
	{
		if (HasAccessToken())
			INSTANCE->DestroyAcceessToken();
	}

	return 0;
}

int CDropbox::OnSrmmWindowOpened(WPARAM wParam, LPARAM lParam)
{
	MessageWindowEventData *ev = (MessageWindowEventData*)lParam;
	if (ev->uType == MSG_WINDOW_EVT_OPENING && ev->hContact)
	{
		WORD status = db_get_w(ev->hContact, GetContactProto(ev->hContact), "Status", ID_STATUS_OFFLINE);

		BBButton bbd = { sizeof(bbd) };
		bbd.pszModuleName = MODULE;
		if (ev->hContact == GetDefaultContact() || !HasAccessToken() || status == ID_STATUS_OFFLINE)
			bbd.bbbFlags = BBSF_HIDDEN | BBSF_DISABLED;
		else if (INSTANCE->hContactTransfer)
			bbd.bbbFlags = BBSF_DISABLED;

		bbd.dwButtonID = BBB_ID_FILE_SEND;
		CallService(MS_BB_SETBUTTONSTATE, ev->hContact, (LPARAM)&bbd);
	}

	return 0;
}

int CDropbox::OnSrmmButtonPressed(WPARAM wParam, LPARAM lParam)
{
	CustomButtonClickData *cbc = (CustomButtonClickData *)lParam;
	if (!strcmp(cbc->pszModule, MODULE) && cbc->dwButtonId == BBB_ID_FILE_SEND && cbc->hContact)
	{
		INSTANCE->hContactTransfer = cbc->hContact;

		HWND hwnd = (HWND)CallService(MS_FILE_SENDFILE, GetDefaultContact(), 0);

		dcftp[hwnd] = cbc->hContact;
	}

	return 0; 
}

int CDropbox::OnFileDoalogCancelled(WPARAM hContact, LPARAM lParam)
{
	HWND hwnd = (HWND)lParam;
	if (INSTANCE->hContactTransfer == dcftp[hwnd])
	{
		dcftp.erase((HWND)lParam);
		INSTANCE->hContactTransfer = 0;
	}

	return 0;
}

int CDropbox::OnFileDoalogSuccessed(WPARAM hContact, LPARAM lParam)
{
	HWND hwnd = (HWND)lParam;
	if (INSTANCE->hContactTransfer == dcftp[hwnd])
		dcftp.erase((HWND)lParam);

	return 0;
}