summaryrefslogtreecommitdiff
path: root/plugins/XSoundNotify/xsn_main.cpp
blob: 49d45e3a570599de14589e2186c6b45967ced647 (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
/*
Miranda plugin template, originally by Richard Hughes
http://miranda-icq.sourceforge.net/

This file is placed in the public domain. Anybody is free to use or
modify it as they wish with no restriction.
There is no warranty.
*/

#include "SettingsDialog.h"

#include <windows.h>
#include <newpluginapi.h>
#include <m_langpack.h>
#include <m_clist.h>
#include <m_skin.h>
#include <m_database.h>
#include <m_protocols.h>
#include "xsn_utils.h"
//#include "DebugLogger.hpp"

HINSTANCE hInst;
PLUGINLINK *pluginLink;
HANDLE AddEventHook;
	
PLUGININFOEX pluginInfo = {
	sizeof(PLUGININFOEX),                // Ðàçìåð ñòóêòóðû
	"XSoundNotify",                		// Êîðîòêîå èìÿ ïëàãèíâ
	PLUGIN_MAKE_VERSION(1,0,0,0),            // Âåðñèÿ ïëàãèíà
	"Provides extended options for sound notifications",                 // Îïèñàíèå ïëàãèíà
	"Roman Torsten",                // Àâòîð
	"rs_torsten-public@yahoo.com",                // Àäðåññ àâòîðà
	"© 2011 Copyright",                // Êîïèðàéò
	"https://plus.google.com/117081718640940130539",        // Àäðåññ ñàéòà ðàçðàáîò÷èêà ïëàãèíà
	0,
	0,
    {0x8b86253, 0xec6e, 0x4d09, { 0xb7, 0xa9, 0x64, 0xac, 0xdf, 0x6, 0x27, 0xb8 }} //{08B86253-EC6E-4d09-B7A9-64ACDF0627B8}
};

extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
{
	hInst = hinstDLL;
	return TRUE;
}

static int PluginMenuCommand(WPARAM wParam,LPARAM lParam)
{
	try
	{
		SoundNotifyDataStorage storage(pluginLink);
		storage.init();
		SettingsDialog dlg(storage);
		if (dlg.DoModal() == IDOK)
			storage.commit();	
	}
	catch (...)
	{
		MessageBox(0, TEXT("Unknown error occured while configuring"), TEXT("XSoundNotify Error"), MB_OK | MB_ICONERROR);
	}

	return 0;
}

extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
{
	return &pluginInfo;
}

static const MUUID interfaces[] = {MIID_TESTPLUGIN, MIID_LAST};
extern "C" __declspec(dllexport) const MUUID* MirandaPluginInterfaces(void)
{
	return interfaces;
}

INT processEvent(WPARAM wParam, LPARAM lParam)
{
	try
	{
		if (!isReceiveMessage(lParam))
			return 0;
						
		xsn_string sound = getContactSound((HANDLE)wParam);
		if (!sound.empty())		
			PlaySound(sound.c_str(), nullptr, SND_ASYNC | SND_FILENAME);		
	}
	catch (std::exception & )
	{
		// log 
	}
	catch (...)
	{
		// log
	}

	return 0;
}

extern "C" int __declspec(dllexport) Load(PLUGINLINK *link)
{
	CLISTMENUITEM mi;

	pluginLink=link;
	CreateServiceFunction("XSoundNotify/MenuCommand", PluginMenuCommand);
	ZeroMemory(&mi,sizeof(mi));
	mi.cbSize=sizeof(mi);
	mi.position=-0x7FFFFFFF;
	mi.flags=0;
	mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA);
	mi.pszName=LPGEN("&XSoundNotify Plugin");
	mi.pszService="XSoundNotify/MenuCommand";
	CallService(MS_CLIST_ADDMAINMENUITEM,0,(LPARAM)&mi);
	AddEventHook = HookEvent(ME_DB_EVENT_ADDED, processEvent);	

	return 0;
}

extern "C" int __declspec(dllexport) Unload(void)
{
	UnhookEvent(AddEventHook);
	return 0;
}