summaryrefslogtreecommitdiff
path: root/plugins/W7ui/jumplist.cpp
blob: 4fd1a68e9d8119be0a3f79a15c353f0261216beb (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 "headers.h"

static HANDLE hProcessJumpList = 0;

static void ProcessJumpListImpl(char *arg)
{
	char *prefix = mir_strdup(arg);
	char *argument = strchr(prefix, ':');
	if (argument) *argument++ = 0;
	NotifyEventHooks(hProcessJumpList, (WPARAM)prefix, (LPARAM)argument);
	mir_free(prefix);
}

static LRESULT CALLBACK MirandaJumpListProcessorWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_COPYDATA:
		{
			COPYDATASTRUCT *data = (COPYDATASTRUCT *)lParam;
			ProcessJumpListImpl((char *)data->lpData);
			break;
		}
	}

	return DefWindowProc(hwnd, message, wParam, lParam);
}

extern "C" __declspec(dllexport) void ProcessJumpList(HWND, HINSTANCE, LPSTR arg, UINT)
{
	char miranda_path[MAX_PATH];
	GetModuleFileNameA(g_hInst, miranda_path, SIZEOF(miranda_path));
	lstrcpyA(strstr(_strlwr(miranda_path), "plugins\\w7ui.dll"), "miranda32.exe");

	if (HWND hwnd = FindWindowA("MirandaJumpListProcessor", miranda_path))
	{
		COPYDATASTRUCT data = {0};
		data.dwData = 0;
		data.cbData = lstrlenA(arg) + 1;
		data.lpData = arg;
		SendMessage(hwnd, WM_COPYDATA, 0, (LPARAM)&data);
	} else
	{
		char command[MAX_PATH * 2];
		wsprintfA(command, "\"%s\" -jump %s", miranda_path, arg);
		WinExec(command, SW_SHOWNORMAL);
	}
}

static int OnJumpListItems(WPARAM, LPARAM lParam)
{
	WCHAR *category = (WCHAR *)lParam;

	if (!category)
	{
		MJumpList_AddItem(SKINICON_STATUS_ONLINE,    TranslateT("Online"),         L"status", L"online");
		MJumpList_AddItem(SKINICON_STATUS_DND,       TranslateT("Do not disturb"), L"status", L"dnd");
		MJumpList_AddItem(SKINICON_STATUS_INVISIBLE, TranslateT("Invisible"),      L"status", L"invisible");
		MJumpList_AddItem(SKINICON_STATUS_OFFLINE,   TranslateT("Offline"),        L"status", L"offline");
		return 0;
	}

	return 0;
}

static int OnJumpListProcess(WPARAM wParam, LPARAM lParam)
{
	char *prefix = (char *)wParam;
	char *argument = (char *)lParam;

	if (!lstrcmpA(prefix, "status"))
	{
		if (!lstrcmpA(argument, "online"))
		{
			CallService(MS_CLIST_SETSTATUSMODE, ID_STATUS_ONLINE, 0);
		} else
		if (!lstrcmpA(argument, "dnd"))
		{
			CallService(MS_CLIST_SETSTATUSMODE, ID_STATUS_DND, 0);
		} else
		if (!lstrcmpA(argument, "invisible"))
		{
			CallService(MS_CLIST_SETSTATUSMODE, ID_STATUS_INVISIBLE, 0);
		} else
		if (!lstrcmpA(argument, "offline"))
		{
			CallService(MS_CLIST_SETSTATUSMODE, ID_STATUS_OFFLINE, 0);
		}
		return 1;
	}

	return 0;
}

void LoadJumpList()
{
	hProcessJumpList = CreateHookableEvent(ME_JUMPLIST_PROCESS);
}

void InitJumpList()
{
	HookEvent(ME_JUMPLIST_BUILDITEMS, OnJumpListItems);
	HookEvent(ME_JUMPLIST_PROCESS, OnJumpListProcess);

	if (char *cmd = strstr(GetCommandLineA(), " -jump "))
		ProcessJumpListImpl(cmd + 7);

	WNDCLASSEX wcx = {0};
	wcx.cbSize = sizeof(wcx);
	wcx.lpfnWndProc = MirandaJumpListProcessorWndProc;
	wcx.hInstance = g_hInst;
	wcx.lpszClassName = _T("MirandaJumpListProcessor");
	RegisterClassEx(&wcx);

	char miranda_path[MAX_PATH];
	GetModuleFileNameA(g_hInst, miranda_path, SIZEOF(miranda_path));
	lstrcpyA(strstr(_strlwr(miranda_path), "plugins\\w7ui.dll"), "miranda32.exe");

	HWND hwnd = CreateWindowA("MirandaJumpListProcessor", miranda_path, 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, HWND_DESKTOP, NULL, g_hInst, NULL);
	ShowWindow(hwnd, SW_HIDE);

	CJumpListBuilder::Rebuild();
}