summaryrefslogtreecommitdiff
path: root/plugins/W7UI/src/jumplistbuilder.cpp
blob: 5e5f1d9f65111a49e12cbdd3234fd32743ddd028 (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
#include "headers.h"

CJumpListBuilder *CJumpListBuilder::m_instance = 0;

CJumpListBuilder::CJumpListBuilder()
{
	m_hBuildCategories = CreateHookableEvent(ME_JUMPLIST_BUILDCATEGORIES);
	m_hBuildItems = CreateHookableEvent(ME_JUMPLIST_BUILDITEMS);
	CreateSvc(MS_JUMPLIST_REBUILD, &CJumpListBuilder::Rebuild);
	CreateSvc(MS_JUMPLIST_ADDCATEGORY, &CJumpListBuilder::AddCategory);
	CreateSvc(MS_JUMPLIST_ADDITEM, &CJumpListBuilder::AddItem);
}

CJumpListBuilder::~CJumpListBuilder()
{
	KillObjectServices(this);
	DestroyHookableEvent(m_hBuildCategories);
	DestroyHookableEvent(m_hBuildItems);
}

void CJumpListBuilder::BuildJumpList()
{
	m_lists = new LIST<TCHAR>(5, _tcscmp);
	NotifyEventHooks(m_hBuildCategories, 0, 0);

	UINT maxSlots;
	IObjectArray *pRemoved;
	CoCreateInstance(CLSID_CustomDestinationList, NULL, CLSCTX_INPROC_SERVER, IID_ICustomDestinationList, (void **)&m_pList);
	m_pList->BeginList(&maxSlots, IID_IObjectArray, (void **)&pRemoved);
	BuildCategory(NULL);
	for (int i = 0; i < m_lists->getCount(); ++i)
		BuildCategory((*m_lists)[i]);
	m_pList->CommitList();
	m_pList->Release();
	pRemoved->Release();

	m_lists->destroy();
	delete m_lists;
}

int __cdecl CJumpListBuilder::Rebuild(WPARAM wParam, LPARAM lParam)
{
	BuildJumpList();
	return 0;
}

int __cdecl CJumpListBuilder::AddCategory(WPARAM wParam, LPARAM lParam)
{
	TCHAR *category = (TCHAR *)lParam;
	if (!m_lists->find(category)) m_lists->insert(mir_wstrdup(category));
	return 0;
}

int __cdecl CJumpListBuilder::AddItem(WPARAM wParam, LPARAM lParam)
{
	MIRANDAJUMPLISTITEM *item = (MIRANDAJUMPLISTITEM *)lParam;
	switch (item->iconSource)
	{
	case MIS_ICOLIB:
		m_pCurrentList->AddItem(item->iconName, item->szTitle, _T("rundll32.exe"), BuildJumpListCommand(item->szPrefix, item->szArgument));
		break;
	case MIS_GENERAL:
		m_pCurrentList->AddItem(item->iconIdx, item->szTitle, _T("rundll32.exe"), BuildJumpListCommand(item->szPrefix, item->szArgument));
		break;
	case MIS_PROTOCOL:
		m_pCurrentList->AddItem(item->iconName, item->iconIdx, item->szTitle, _T("rundll32.exe"), BuildJumpListCommand(item->szPrefix, item->szArgument));
		break;
	}
	return 0;
}

void CJumpListBuilder::BuildCategory(TCHAR *category)
{
	m_pCurrentList = new CJumpListArray;
	NotifyEventHooks(m_hBuildItems, 0, (LPARAM)category);

	if (category)
		m_pList->AppendCategory(category, m_pCurrentList->GetArray());
	else
		m_pList->AddUserTasks(m_pCurrentList->GetArray());
	delete m_pCurrentList;

}

TCHAR *CJumpListBuilder::BuildJumpListCommand(TCHAR *prefix, TCHAR *argument)
{
	TCHAR path[MAX_PATH];
	GetModuleFileName(g_hInst, path, SIZEOF(path));
	mir_sntprintf(m_cmdBuf, SIZEOF(m_cmdBuf), _T("\"%s\",ProcessJumpList %s:%s"), path, prefix, argument);
	return m_cmdBuf;
}

HANDLE CJumpListBuilder::CreateSvc(char *svc, int (__cdecl CJumpListBuilder::*fn)(WPARAM, LPARAM))
{
	return CreateServiceFunctionObj(svc, *(MIRANDASERVICEOBJ *)&fn, this);
}

/*
static TCHAR *BuildJumpListCommand(TCHAR *buf, int size, TCHAR *arg);

static void SetupTasks()
{
	TCHAR buf[MAX_PATH * 2];

	CJumpListArray tasks;
	tasks.AddItem(SKINICON_STATUS_ONLINE, TranslateT("Online"), _T("rundll32.exe"), BuildJumpListCommand(buf, SIZEOF(buf), _T("status:online")));
	tasks.AddItem(SKINICON_STATUS_DND, TranslateT("Do not disturb"), _T("rundll32.exe"), BuildJumpListCommand(buf, SIZEOF(buf), _T("status:dnd")));
	tasks.AddItem(SKINICON_STATUS_INVISIBLE, TranslateT("Invisible"), _T("rundll32.exe"), BuildJumpListCommand(buf, SIZEOF(buf), _T("status:invisible")));
	tasks.AddItem(SKINICON_STATUS_OFFLINE, TranslateT("Offline"), _T("rundll32.exe"), BuildJumpListCommand(buf, SIZEOF(buf), _T("status:offline")));

//	CJumpListArray contacts;
//	contacts.AddItem("core_status_*0", TranslateT("Nickname"), L"taskhost.exe", L"profile.dat -contact:hcontact");

	UINT maxSlots;
	IObjectArray *pRemoved;

	ICustomDestinationList *pList;
	CoCreateInstance(CLSID_CustomDestinationList, NULL, CLSCTX_INPROC_SERVER, IID_ICustomDestinationList, (void **)&pList);
	pList->BeginList(&maxSlots, IID_IObjectArray, (void **)&pRemoved);
	pList->AddUserTasks(tasks.GetArray());
//	pList->AppendCategory(L"Contacts", contacts.GetArray());
	pList->CommitList();
	pList->Release();

	pRemoved->Release();
}
*/