summaryrefslogtreecommitdiff
path: root/plugins/FileAsMessage/src/main.cpp
blob: 4bc31d1a8fad43f96f833819eda41aa77e04e598 (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
#include "main.h"

PLUGININFOEX pluginInfo =
{
	sizeof(PLUGININFOEX),
	__PLUGIN_NAME,
	PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
	__DESCRIPTION,
	__AUTHOR,
	__AUTHOREMAIL,
	__COPYRIGHT,
	__AUTHORWEB,
	UNICODE_AWARE,
	// {34B5A402-1B79-4246-B041-43D0B590AE2C}
	{0x34b5a402, 0x1b79, 0x4246, {0xb0, 0x41, 0x43, 0xd0, 0xb5, 0x90, 0xae, 0x2c}}
};

HANDLE hFileList;
HINSTANCE hInst;
int hLangpack;

char *szServiceTitle = SERVICE_TITLE;
char *szServicePrefix = SERVICE_PREFIX;
HANDLE hHookDbSettingChange, hHookContactAdded, hHookSkinIconsChanged;

HICON hIcons[5];

static IconItem iconList[] = 
{
	{ LPGEN("Play"), "FePlay", IDI_PLAY },
	{ LPGEN("Pause"), "FePause", IDI_PAUSE },
	{ LPGEN("Revive"), "FeRefresh", IDI_REFRESH },
	{ LPGEN("Stop"), "FeStop", IDI_STOP },
	{ LPGEN("Main"), "FeMain", IDI_SMALLICON },
};

int iIconId[5] = {3,2,4,1,0};

//
//  wParam - Section name
//  lParam - Icon ID
//
int OnSkinIconsChanged(WPARAM wParam,LPARAM lParam)
{
	for(int indx = 0; indx < SIZEOF(hIcons); indx++)
		hIcons[indx] = Skin_GetIconByHandle( iconList[indx].hIcolib );

	WindowList_Broadcast(hFileList, WM_FE_SKINCHANGE, 0,0);

	return 0;
}

int OnSettingChanged(WPARAM hContact, LPARAM lParam)
{
	DBCONTACTWRITESETTING *cws=(DBCONTACTWRITESETTING*)lParam;

	HWND hwnd = WindowList_Find(hFileList, hContact);
	PostMessage(hwnd, WM_FE_STATUSCHANGE, 0,0);
	return 0;
}

INT_PTR OnRecvFile(WPARAM wParam, LPARAM lParam)
{
	CLISTEVENT *clev = (CLISTEVENT*)lParam;

	HWND hwnd = WindowList_Find(hFileList, clev->hContact);
	if(IsWindow(hwnd))
	{
		ShowWindow(hwnd, SW_SHOWNORMAL);
		SetForegroundWindow(hwnd);
		SetFocus(hwnd);
	}
	/*
	else
	{
		if(hwnd != 0) WindowList_Remove(hFileList, hwnd);
		FILEECHO *fe = new FILEECHO((HANDLE)clev->hContact);
		fe->inSend = FALSE;
		hwnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, (DLGPROC)DialogProc, (LPARAM)fe);
		if(hwnd == NULL)
		{
			delete fe;
			return 0;
		}
		//SendMessage(hwnd, WM_FE_SERVICE, 0, TRUE);
		ShowWindow(hwnd, SW_SHOWNORMAL);
	}
	*/
	return 1;
}

INT_PTR OnSendFile(WPARAM wParam, LPARAM lParam)
{
	HWND hwnd = WindowList_Find(hFileList, wParam);
	if(IsWindow(hwnd))
	{
		SetForegroundWindow(hwnd);
		SetFocus(hwnd);
	}
	else
	{
		if(hwnd != 0) WindowList_Remove(hFileList, hwnd);
		FILEECHO *fe = new FILEECHO(wParam);
		fe->inSend = TRUE;
		hwnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, DialogProc, (LPARAM)fe);
		if(hwnd == NULL)
		{
			delete fe;
			return 0;
		}
		//SendMessage(hwnd, WM_FE_SERVICE, 0, TRUE);
		ShowWindow(hwnd, SW_SHOWNORMAL);
	}
	return 1;
}

INT_PTR OnRecvMessage(WPARAM wParam, LPARAM lParam)
{
	CCSDATA *pccsd = (CCSDATA *)lParam;
	PROTORECVEVENT *ppre = ( PROTORECVEVENT * )pccsd->lParam;

	if(strncmp(ppre->szMessage, szServicePrefix, strlen(szServicePrefix)))
		return CallService(MS_PROTO_CHAINRECV, wParam, lParam);

	HWND hwnd = WindowList_Find(hFileList, pccsd->hContact);
	if(!IsWindow(hwnd))
	{
		if(hwnd != 0) WindowList_Remove(hFileList, hwnd);
		FILEECHO *fe = new FILEECHO(pccsd->hContact);
		fe->inSend = FALSE;
		hwnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, DialogProc, (LPARAM)fe);
		if(hwnd == NULL)
		{
			delete fe;
			return 0;
		}
	}
	char *msg = strdup(ppre->szMessage + strlen(szServicePrefix));
	PostMessage(hwnd, WM_FE_MESSAGE, (WPARAM)pccsd->hContact, (LPARAM)msg);

	return 0;
}

int OnOptInitialise(WPARAM wParam, LPARAM lParam)
{
	OPTIONSDIALOGPAGE odp = { 0 };
	odp.hInstance = hInst;
	odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS);
	odp.ptszTitle = _T(SERVICE_TITLE);
	odp.ptszGroup = LPGENT("Events");
	odp.flags = ODPF_BOLDGROUPS|ODPF_TCHAR;
	odp.pfnDlgProc = OptionsDlgProc;
	Options_AddPage(wParam, &odp);
	return 0;
}

//
// MirandaPluginInfo()
// Called by Miranda to get Version
//
extern "C" __declspec(dllexport) PLUGININFOEX *MirandaPluginInfoEx(DWORD dwVersion)
{
	return &pluginInfo;
}

//
// Startup initializing
//

static int OnModulesLoaded(WPARAM wparam,LPARAM lparam)
{
	for(int indx = 0; indx < SIZEOF(hIcons); indx++)
		hIcons[indx] = Skin_GetIconByHandle( iconList[indx].hIcolib );

	hHookSkinIconsChanged = HookEvent(ME_SKIN2_ICONSCHANGED, OnSkinIconsChanged);

	CLISTMENUITEM mi = { sizeof(mi) };
	mi.position = 200011;
	mi.hIcon = hIcons[ICON_MAIN];
	mi.pszName = LPGEN("File As Message...");
	mi.pszService = SERVICE_NAME "/FESendFile";
	mi.pszContactOwner = NULL;
	mi.flags = CMIF_NOTOFFLINE;
	Menu_AddContactMenuItem(&mi);
	return 0;
}

extern "C" __declspec(dllexport) int Load(void)
{
	mir_getLP(&pluginInfo);

	InitCRC32();

	Icon_Register(hInst, "fileAsMessage", iconList, SIZEOF(iconList));

	hFileList = WindowList_Create();

	CreateServiceFunction(SERVICE_NAME PSR_MESSAGE, OnRecvMessage);
	CreateServiceFunction(SERVICE_NAME "/FESendFile", OnSendFile);
	CreateServiceFunction(SERVICE_NAME "/FERecvFile", OnRecvFile);

	PROTOCOLDESCRIPTOR pd = { sizeof(pd) };
	pd.szName = SERVICE_NAME;
	pd.type = PROTOTYPE_FILTER;
	CallService(MS_PROTO_REGISTERMODULE, 0, ( LPARAM ) &pd);

	HookEvent(ME_OPT_INITIALISE, OnOptInitialise);
	HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
	hHookDbSettingChange = HookEvent(ME_DB_CONTACT_SETTINGCHANGED, OnSettingChanged);
	hHookSkinIconsChanged = NULL;

	return 0;
}

//
// Unload()
// Called by Miranda when Plugin is unloaded.
//
extern "C" __declspec(dllexport) int Unload(void)
{
	WindowList_Destroy(hFileList);
	if(hHookSkinIconsChanged != NULL)
		UnhookEvent(hHookSkinIconsChanged);
	UnhookEvent(hHookDbSettingChange);
	UnhookEvent(hHookContactAdded);

	return 0;
}

//
// DllMain()
//
int WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID pReserved)
{
	hInst = hInstance;
	return TRUE;
}