summaryrefslogtreecommitdiff
path: root/protocols/MSN/src/msn_menu.cpp
blob: 30a6c28b25c0d3a83010ec8832693aab9fc73d1e (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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
/*
Plugin of Miranda IM for communicating with users of the MSN Messenger protocol.

Copyright (c) 2012-2017 Miranda NG Team
Copyright (c) 2006-2012 Boris Krasnovskiy.
Copyright (c) 2003-2005 George Hazan.
Copyright (c) 2002-2003 Richard Hughes (original version).

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; either version 2
of the License, or (at your option) any later version.

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"
#include "msn_proto.h"

static HGENMENU hBlockMenuItem, hLiveSpaceMenuItem, hNetmeetingMenuItem, hChatInviteMenuItem, hOpenInboxMenuItem;

HANDLE hNetMeeting, hBlockCom, hSendHotMail, hInviteChat, hViewProfile;

// Block command callback function
INT_PTR CMsnProto::MsnBlockCommand(WPARAM hContact, LPARAM)
{
	if (msnLoggedIn) {
		char tEmail[MSN_MAX_EMAIL_LEN];
		if (db_get_static(hContact, m_szModuleName, "wlid", tEmail, sizeof(tEmail))
				&& db_get_static(hContact, m_szModuleName, "e-mail", tEmail, sizeof(tEmail)))
			return 0;

		if (Lists_IsInList(LIST_BL, tEmail))
			delSetting(hContact, "ApparentMode");
		else
			setWord(hContact, "ApparentMode", ID_STATUS_OFFLINE);
	}
	return 0;
}

// MsnGotoInbox - goes to the Inbox folder at the live.com
INT_PTR CMsnProto::MsnGotoInbox(WPARAM, LPARAM)
{
	MCONTACT hContact = MSN_HContactFromEmail(MyOptions.szEmail);
	if (hContact)
		pcli->pfnRemoveEvent(hContact, 1);

	MsnInvokeMyURL(true, "http://mail.live.com?rru=inbox");
	return 0;
}

INT_PTR CMsnProto::MsnSendHotmail(WPARAM hContact, LPARAM)
{
	char szEmail[MSN_MAX_EMAIL_LEN];
	if (MSN_IsMeByContact(hContact, szEmail))
		MsnGotoInbox(0, 0);
	else if (msnLoggedIn)
		MsnInvokeMyURL(true, CMStringA().Format("http://mail.live.com?rru=compose?to=%s", ptrA(mir_urlEncode(szEmail))));

	return 0;
}

// MsnSetupAlerts - goes to the alerts section at the live.com
INT_PTR CMsnProto::MsnSetupAlerts(WPARAM, LPARAM)
{
	MsnInvokeMyURL(false, "http://alerts.live.com");
	return 0;
}

// MsnViewProfile - view a contact's profile
INT_PTR CMsnProto::MsnViewProfile(WPARAM hContact, LPARAM)
{
	char buf[64], *cid;

	if (hContact == NULL)
		cid = mycid;
	else {
		cid = buf;
		if (db_get_static(hContact, m_szModuleName, "CID", buf, 30))
			return 0;
	}

	char tUrl[256];
	mir_snprintf(tUrl, "http://cid-%I64X.profiles.live.com", _atoi64(cid));
	MsnInvokeMyURL(false, tUrl);
	return 0;
}

// MsnEditProfile - goes to the Profile section at the live.com
INT_PTR CMsnProto::MsnEditProfile(WPARAM, LPARAM)
{
	MsnViewProfile(0, 0);
	return 0;
}

// MsnInviteCommand - invite command callback function
INT_PTR CMsnProto::MsnInviteCommand(WPARAM, LPARAM)
{
	DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, DlgInviteToChat,
		LPARAM(new InviteChatParam(NULL, NULL, this)));
	return 0;
}

// MsnRebuildContactMenu - gray or ungray the block menus according to contact's status
int CMsnProto::OnPrebuildContactMenu(WPARAM hContact, LPARAM)
{
	if (!MSN_IsMyContact(hContact))
		return 0;

	char szEmail[MSN_MAX_EMAIL_LEN];
	bool isMe = MSN_IsMeByContact(hContact, szEmail);
	if (szEmail[0]) {
		int listId = Lists_GetMask(szEmail);
		bool noChat = !(listId & LIST_FL) || isMe || isChatRoom(hContact);

		Menu_ModifyItem(hBlockMenuItem, (listId & LIST_BL) ? LPGENW("&Unblock") : LPGENW("&Block"));
		Menu_ShowItem(hBlockMenuItem, !noChat);

		Menu_ModifyItem(hOpenInboxMenuItem, isMe ? LPGENW("Open &Hotmail Inbox") : LPGENW("Send &Hotmail E-mail"));
		Menu_ShowItem(hOpenInboxMenuItem, emailEnabled);

#ifdef OBSOLETE
		Menu_ShowItem(hNetmeetingMenuItem, !noChat);
#endif
		Menu_ShowItem(hChatInviteMenuItem, !noChat);
	}

	return 0;
}

int CMsnProto::OnContactDoubleClicked(WPARAM hContact, LPARAM)
{
	if (emailEnabled && MSN_IsMeByContact(hContact)) {
		MsnSendHotmail(hContact, 0);
		return 1;
	}
	return 0;
}

#ifdef OBSOLETE
// MsnSendNetMeeting - Netmeeting callback function
INT_PTR CMsnProto::MsnSendNetMeeting(WPARAM wParam, LPARAM)
{
	if (!msnLoggedIn) return 0;

	MCONTACT hContact = MCONTACT(wParam);

	char szEmail[MSN_MAX_EMAIL_LEN];
	if (MSN_IsMeByContact(hContact, szEmail)) return 0;

	ThreadData* thread = MSN_GetThreadByContact(szEmail);

	if (thread == NULL) {
		MessageBox(NULL, TranslateT("You must be talking to start Netmeeting"), TranslateT("MSN Protocol"), MB_OK | MB_ICONERROR);
		return 0;
	}

	char msg[1024];

	mir_snprintf(msg,
		"Content-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n"
		"Application-Name: NetMeeting\r\n"
		"Application-GUID: {44BBA842-CC51-11CF-AAFA-00AA00B6015C}\r\n"
		"Session-Protocol: SM1\r\n"
		"Invitation-Command: INVITE\r\n"
		"Invitation-Cookie: %i\r\n"
		"Session-ID: {1A879604-D1B8-11D7-9066-0003FF431510}\r\n\r\n",
		MSN_GenRandom());

	thread->sendMessage('N', NULL, 1, msg, MSG_DISABLE_HDR);
	return 0;
}

static INT_PTR MsnMenuSendNetMeeting(WPARAM wParam, LPARAM lParam)
{
	CMsnProto* ppro = GetProtoInstanceByHContact(wParam);
	return (ppro) ? ppro->MsnSendNetMeeting(wParam, lParam) : 0;
}

//	SetNicknameCommand - sets nick name
static INT_PTR CALLBACK DlgProcSetNickname(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_INITDIALOG:
	{
		TranslateDialogDefault(hwndDlg);

		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
		CMsnProto* proto = (CMsnProto*)lParam;

		Window_SetIcon_IcoLib(hwndDlg, GetIconHandle("main"));
		SendDlgItemMessage(hwndDlg, IDC_NICKNAME, EM_LIMITTEXT, 129, 0);

		DBVARIANT dbv;
		if (!proto->getWString("Nick", &dbv)) {
			SetDlgItemText(hwndDlg, IDC_NICKNAME, dbv.ptszVal);
			db_free(&dbv);
		}
		return TRUE;
	}
	case WM_COMMAND:
		switch (wParam) {
		case IDOK:
		{
			CMsnProto *proto = (CMsnProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
			if (proto->msnLoggedIn) {
				wchar_t str[130];
				GetDlgItemText(hwndDlg, IDC_NICKNAME, str, _countof(str));
				proto->MSN_SendNickname(str);
			}
		}

		case IDCANCEL:
			DestroyWindow(hwndDlg);
			break;
		}
		break;

	case WM_CLOSE:
		DestroyWindow(hwndDlg);
		break;

	case WM_DESTROY:
		ReleaseIconEx("main");
		ReleaseIconEx("main", true);
		break;
	}
	return FALSE;
}

INT_PTR CMsnProto::SetNicknameUI(WPARAM, LPARAM)
{
	HWND hwndSetNickname = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_SETNICKNAME),
		NULL, DlgProcSetNickname, (LPARAM)this);

	SetForegroundWindow(hwndSetNickname);
	SetFocus(hwndSetNickname);
	ShowWindow(hwndSetNickname, SW_SHOW);
	return 0;
}
#endif

// Menus initialization
void CMsnProto::MsnInitMainMenu(void)
{
	CMenuItem mi;
	mi.root = Menu_GetProtocolRoot(this);

#ifdef OBSOLETE
	mi.pszService = MS_SET_NICKNAME_UI;
	CreateProtoService(mi.pszService, &CMsnProto::SetNicknameUI);
	mi.position = 201001;
	mi.hIcolibItem = GetIconHandle(IDI_MSN);
	mi.name.a = LPGEN("Set &Nickname");
	menuItemsMain[0] = Menu_AddProtoMenuItem(&mi, m_szModuleName);
#endif

	mi.pszService = MSN_INVITE;
	CreateProtoService(mi.pszService, &CMsnProto::MsnInviteCommand);
	mi.position = 201002;
	mi.hIcolibItem = GetIconHandle(IDI_INVITE);
	mi.name.a = LPGEN("Create &Chat");
	menuItemsMain[0] = Menu_AddProtoMenuItem(&mi, m_szModuleName);

	mi.pszService = MS_GOTO_INBOX;
	CreateProtoService(mi.pszService, &CMsnProto::MsnGotoInbox);
	mi.position = 201003;
	mi.hIcolibItem = GetIconHandle(IDI_INBOX);
	mi.name.a = LPGEN("Display &Hotmail Inbox");
	menuItemsMain[1] = Menu_AddProtoMenuItem(&mi, m_szModuleName);

	mi.pszService = MS_EDIT_PROFILE;
	CreateProtoService(mi.pszService, &CMsnProto::MsnEditProfile);
	mi.position = 201004;
	mi.hIcolibItem = GetIconHandle(IDI_PROFILE);
	mi.name.a = LPGEN("View &Profile");
	menuItemsMain[2] = Menu_AddProtoMenuItem(&mi, m_szModuleName);

	mi.pszService = MS_EDIT_ALERTS;
	CreateProtoService(mi.pszService, &CMsnProto::MsnSetupAlerts);
	mi.position = 201004;
	mi.hIcolibItem = GetIconHandle(IDI_PROFILE);
	mi.name.a = LPGEN("Setup Live &Alerts");
	menuItemsMain[3] = Menu_AddProtoMenuItem(&mi, m_szModuleName);

	MSN_EnableMenuItems(m_iStatus >= ID_STATUS_ONLINE);
}

void CMsnProto::MSN_EnableMenuItems(bool bEnable)
{
	for (int i = 0; i < _countof(menuItemsMain); i++)
		Menu_ModifyItem(menuItemsMain[i], NULL, INVALID_HANDLE_VALUE, bEnable ? 0 : CMIF_GRAYED);

	if (bEnable)
		Menu_ShowItem(menuItemsMain[1], emailEnabled);
}

//////////////////////////////////////////////////////////////////////////////////////

static CMsnProto* GetProtoInstanceByHContact(MCONTACT hContact)
{
	char* szProto = GetContactProto(hContact);
	if (szProto == NULL)
		return NULL;

	for (int i = 0; i < g_Instances.getCount(); i++)
		if (!mir_strcmp(szProto, g_Instances[i].m_szModuleName))
			return &g_Instances[i];

	return NULL;
}

static INT_PTR MsnMenuBlockCommand(WPARAM wParam, LPARAM lParam)
{
	CMsnProto* ppro = GetProtoInstanceByHContact(wParam);
	return (ppro) ? ppro->MsnBlockCommand(wParam, lParam) : 0;
}

static INT_PTR MsnMenuViewProfile(WPARAM wParam, LPARAM lParam)
{
	CMsnProto* ppro = GetProtoInstanceByHContact(wParam);
	return (ppro) ? ppro->MsnViewProfile(wParam, lParam) : 0;
}

static INT_PTR MsnMenuSendHotmail(WPARAM wParam, LPARAM lParam)
{
	CMsnProto* ppro = GetProtoInstanceByHContact(wParam);
	return (ppro) ? ppro->MsnSendHotmail(wParam, lParam) : 0;
}

static int MSN_OnPrebuildContactMenu(WPARAM wParam, LPARAM lParam)
{
	CMsnProto* ppro = GetProtoInstanceByHContact(wParam);
	if (ppro)
		ppro->OnPrebuildContactMenu(wParam, lParam);
	else {
		Menu_ShowItem(hBlockMenuItem, false);
		Menu_ShowItem(hLiveSpaceMenuItem, false);
#ifdef OBSOLETE
		Menu_ShowItem(hNetmeetingMenuItem, false);
#endif
		Menu_ShowItem(hChatInviteMenuItem, false);
		Menu_ShowItem(hOpenInboxMenuItem, false);
	}

	return 0;
}

void MSN_InitContactMenu(void)
{
	char servicefunction[100];
	mir_strcpy(servicefunction, "MSN");
	char* tDest = servicefunction + mir_strlen(servicefunction);

	CMenuItem mi;
	mi.pszService = servicefunction;

	SET_UID(mi, 0xc6169b8f, 0x53ab, 0x4242, 0xbe, 0x90, 0xe2, 0x4a, 0xa5, 0x73, 0x88, 0x32);
	mir_strcpy(tDest, MSN_BLOCK);
	hBlockCom = CreateServiceFunction(servicefunction, MsnMenuBlockCommand);
	mi.position = -500050000;
	mi.hIcolibItem = GetIconHandle(IDI_MSNBLOCK);
	mi.name.a = LPGEN("&Block");
	hBlockMenuItem = Menu_AddContactMenuItem(&mi);

	SET_UID(mi, 0x7f7e4c24, 0x821c, 0x450f, 0x93, 0x76, 0xbe, 0x65, 0xe9, 0x2f, 0xb6, 0xc2);
	mir_strcpy(tDest, MSN_VIEW_PROFILE);
	hViewProfile = CreateServiceFunction(servicefunction, MsnMenuViewProfile);
	mi.position = -500050003;
	mi.hIcolibItem = GetIconHandle(IDI_PROFILE);
	mi.name.a = LPGEN("View &Profile");
	hLiveSpaceMenuItem = Menu_AddContactMenuItem(&mi);

#ifdef OBSOLETE
	mir_strcpy(tDest, MSN_NETMEETING);
	hNetMeeting = CreateServiceFunction(servicefunction, MsnMenuSendNetMeeting);
	mi.flags = CMIF_NOTOFFLINE;
	mi.position = -500050002;
	mi.hIcolibItem = GetIconHandle(IDI_NETMEETING);
	mi.name.a = LPGEN("&Start Netmeeting");
	hNetmeetingMenuItem = Menu_AddContactMenuItem(&mi);
#endif

	SET_UID(mi,0x25a007c0, 0x8dc7, 0x4284, 0x8a, 0x5e, 0x2, 0x83, 0x17, 0x5d, 0x52, 0xea);
	mir_strcpy(tDest, "/SendHotmail");
	hSendHotMail = CreateServiceFunction(servicefunction, MsnMenuSendHotmail);
	mi.position = -2000010005;
	mi.flags = CMIF_HIDDEN;
	mi.hIcolibItem = Skin_GetIconHandle(SKINICON_OTHER_SENDEMAIL);
	mi.name.a = LPGEN("Open &Hotmail Inbox");
	hOpenInboxMenuItem = Menu_AddContactMenuItem(&mi);

	HookEvent(ME_CLIST_PREBUILDCONTACTMENU, MSN_OnPrebuildContactMenu);
}

void MSN_RemoveContactMenus(void)
{
	Menu_RemoveItem(hBlockMenuItem);
	Menu_RemoveItem(hLiveSpaceMenuItem);
#ifdef OBSOLETE
	Menu_RemoveItem(hNetmeetingMenuItem);
	DestroyServiceFunction(hNetMeeting);
#endif
	Menu_RemoveItem(hChatInviteMenuItem);
	Menu_RemoveItem(hOpenInboxMenuItem);

	DestroyServiceFunction(hBlockCom);
	DestroyServiceFunction(hSendHotMail);
	DestroyServiceFunction(hInviteChat);
	DestroyServiceFunction(hViewProfile);
}