summaryrefslogtreecommitdiff
path: root/MySpace/menu.cpp
blob: 196c3e56cf21ce2fd98a25411cceefb86691b55b (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
#include "common.h"
#include "menu.h"
#include "resource.h"
#include "server_con.h"

HANDLE hMenuMain = 0, hServiceMenuMain = 0;

int MainMenuService(WPARAM wParam, LPARAM lParam) {
	// TODO: add code here that executes when the menu item is chosen

	// e.g. modify main menu item - see m_clist.h
	//CLISTMENUITEM menu = {0};
	//menu.cbSize=sizeof(menu);
	//menu.flags = CMIM_NAME | CMIF_TCHAR;
	//menu.ptszName = (char *)TranslateT("Changed menu text");
	//CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuMain, (LPARAM)&menu);
		
	CallService(MS_UTILS_OPENURL, (WPARAM)TRUE, (LPARAM)"http://home.myspace.com/index.cfm?fuseaction=user");

	return 0;
}

HANDLE hMenuContact = 0, hServiceMenuContact = 0, hEventMenuBuild = 0;

int ContactMenuService(WPARAM wParam, LPARAM lParam) {
	HANDLE hContact = (HANDLE)wParam;
	int uid;
	if((uid = DBGetContactSettingDword(hContact, MODULE, "UID", 0)) != 0) {
		char buff[512];
		mir_snprintf(buff, 512, "http://www.myspace.com/%d", uid);
		CallService(MS_UTILS_OPENURL, (WPARAM)TRUE, (LPARAM)buff);
	}
	return 0;
}

// this function is called when the contact's menu is about to be shown - you can e.g. 
// modify the menu here using the MS_CLIST_MODIFYMENUITEM service
int PrebuildContactMenu(WPARAM wParam, LPARAM lParam) {
	HANDLE hContact = (HANDLE)wParam;
	// TODO: add code here that executes when the menu is constructed

	// e.g. modify menu item - see m_clist.h
	//CLISTMENUITEM menu = {0};
	//menu.cbSize=sizeof(menu);
	//menu.flags = CMIM_NAME | CMIF_TCHAR;
	//menu.ptszName = (char *)TranslateT("Changed menu text");
	//CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuContact, (LPARAM)&menu);

	return 0;
}

void InitMenu() {
	CLISTMENUITEM menu = {0};
	menu.cbSize=sizeof(menu);
	char buff[512];

	menu.flags = CMIM_ALL | CMIF_TCHAR;
	menu.hIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_MYSPACE), IMAGE_ICON, 0, 0, 0);

	hServiceMenuMain = CreateProtoServiceFunction(MODULE, "/MainMenu", MainMenuService);
	TCHAR tbuff[512];
#ifdef _UNICODE
	MultiByteToWideChar(code_page, 0, MODULE, -1, tbuff, 512);
#else
	strncpy(tbuff, MODULE, 512);
#endif
	menu.ptszName = TranslateTS(tbuff);
	mir_snprintf(buff, 512, "%s%s", MODULE, "/MainMenu");
	menu.pszService = buff;
	menu.position = 2000060000;
	hMenuMain = (HANDLE)CallService(MS_CLIST_ADDMAINMENUITEM,0,(LPARAM)&menu);

	// contact menu item
	hServiceMenuContact = CreateProtoServiceFunction(MODULE, "/ContactMenu", ContactMenuService);
	menu.ptszName = TranslateT("Show profile");
	mir_snprintf(buff, 512, "%s%s", MODULE, "/ContactMenu");
	menu.pszService = buff;
	menu.position = 0;
	//menu.flags |= CMIF_NOTOFFLINE; // only show for not-offline contacts
	hMenuContact = (HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&menu);

	hEventMenuBuild = HookEvent(ME_CLIST_PREBUILDCONTACTMENU, PrebuildContactMenu);
}

void DeinitMenu() {
	UnhookEvent(hEventMenuBuild);
	DestroyServiceFunction(hServiceMenuContact);
	DestroyServiceFunction(hServiceMenuMain);
}