summaryrefslogtreecommitdiff
path: root/protocols/ICQ-WIM/src/main.cpp
blob: 21232e7d25b2092bd07cef26641c6ac842539b37 (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
// -----------------------------------------------------------------------------
// ICQ plugin for Miranda NG
// -----------------------------------------------------------------------------
// Copyright © 2018-19 Miranda NG team
// 
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// -----------------------------------------------------------------------------

#include "stdafx.h"

bool g_bPopupService, g_bSecureIM, g_bMessageState;

HWND g_hwndHeartbeat;

IconItem iconList[] =
{
	{ LPGEN("Email"), "icq_email", IDI_INBOX },
	{ LPGEN("Email notification"), "icq_email_notif", IDI_MAIL_NOTIFY }
};

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

static PLUGININFOEX pluginInfoEx = {
	sizeof(PLUGININFOEX),
	__PLUGIN_NAME,
	PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
	__DESCRIPTION,
	__AUTHOR,
	__COPYRIGHT,
	__AUTHORWEB,
	UNICODE_AWARE,
	{ 0xEFB2355B, 0x82B3, 0x4759, { 0xb7, 0xd8, 0x95, 0xf8, 0xe9, 0x50, 0x62, 0x91 } } // {EFB2355B-82B3-4759-B7D8-95F8E9506291}
};

CMPlugin g_plugin;

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

struct CMPluginMra : public ACCPROTOPLUGIN<CIcqProto>
{
	CMPluginMra() : ACCPROTOPLUGIN<CIcqProto>("MRA", pluginInfoEx)
	{
		SetUniqueId(DB_KEY_ID);
	}

	void Register()
	{
		m_hInst = g_plugin.getInst();
		RegisterProtocol(PROTOTYPE_PROTOCOL, g_plugin.fnInit, g_plugin.fnUninit);
	}
}
static g_pluginMra;

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

CMPlugin::CMPlugin() :
	ACCPROTOPLUGIN<CIcqProto>(MODULENAME, pluginInfoEx)
{
	SetUniqueId(DB_KEY_ID);
}

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

extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOCOL, MIID_LAST };

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

static int OnContactMenu(WPARAM hContact, LPARAM lParam)
{
	Menu_ShowItem(g_plugin.m_hmiRoot, false);

	CIcqProto *proto = CMPlugin::getInstance(hContact);
	return proto ? proto->OnContactMenu(hContact, lParam) : 0;
}

static INT_PTR ICQPermitDeny(WPARAM hContact, LPARAM, LPARAM bAllow)
{
	CIcqProto *proto = CMPlugin::getInstance(hContact);
	if (proto)
		proto->SetPermitDeny(proto->GetUserId(hContact), bAllow != 0);
	return 0;
}

static int ModuleLoad(WPARAM, LPARAM)
{
	g_bSecureIM = ServiceExists("SecureIM/IsContactSecured");
	g_bPopupService = ServiceExists(MS_POPUP_ADDPOPUPW);
	g_bMessageState = ServiceExists(MS_MESSAGESTATE_UPDATE);
	return 0;
}

static int OnModulesLoaded(WPARAM, LPARAM)
{
	ModuleLoad(0, 0);

	// init menus
	CMenuItem mi(&g_plugin);

	SET_UID(mi, 0x9cd3a933, 0x3bd5, 0x4d1c, 0xbd, 0xf1, 0xa8, 0xf9, 0xbf, 0xf0, 0xd7, 0x28);
	mi.position = 100000;
	mi.name.a = "ICQ";
	mi.hIcolibItem = Skin_LoadProtoIcon(g_plugin.getModule(), ID_STATUS_ONLINE);
	g_plugin.m_hmiRoot = Menu_AddContactMenuItem(&mi);

	mi.flags = CMIF_UNMOVABLE;
	mi.root = g_plugin.m_hmiRoot;
	mi.name.a = LPGEN("Ignore");
	mi.hIcolibItem = Skin_GetIconHandle(SKINICON_AUTH_REVOKE);
	mi.pszService = "ICQ/Ignore";
	g_plugin.m_hmiIgnore = Menu_AddContactMenuItem(&mi);
	CreateServiceFunctionParam(mi.pszService, ICQPermitDeny, 0);

	mi.name.a = LPGEN("Remove Ignore");
	mi.hIcolibItem = Skin_GetIconHandle(SKINICON_AUTH_ADD);
	mi.pszService = "ICQ/RemoveIgnore";
	g_plugin.m_hmiAllow = Menu_AddContactMenuItem(&mi);
	CreateServiceFunctionParam(mi.pszService, ICQPermitDeny, 1);

	HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnContactMenu);
	return 0;
}

int CMPlugin::Load()
{
	// register the second instance of this plugin as MRA
	g_pluginMra.Register();

	g_hwndHeartbeat = CreateWindowEx(0, L"STATIC", nullptr, 0, 0, 0, 0, 0, nullptr, nullptr, nullptr, nullptr);

	registerIcon("Protocols/ICQ", iconList, "ICQ");

	HookEvent(ME_SYSTEM_MODULELOAD, ModuleLoad);
	HookEvent(ME_SYSTEM_MODULEUNLOAD, ModuleLoad);
	HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
	return 0;
}

int CMPlugin::Unload()
{
	DestroyWindow(g_hwndHeartbeat);
	return 0;
}