summaryrefslogtreecommitdiff
path: root/plugins/StopSpamPlus
diff options
context:
space:
mode:
authorKirill Volinsky <KVolinsky@COMMON.EU.CORP.TOYOTA.com>2017-09-18 18:00:12 +0300
committerKirill Volinsky <KVolinsky@COMMON.EU.CORP.TOYOTA.com>2017-09-18 18:00:12 +0300
commitb5de62080a2384e9f66d7bafbf971aa5b4b7c0c1 (patch)
tree23cdae6f0973126efbedd60b8840867e7b6501ba /plugins/StopSpamPlus
parent1836e8aa8a20b7339fd27c67acef67b7eb446da4 (diff)
StopSpamPlus: removed template for hooking events
Diffstat (limited to 'plugins/StopSpamPlus')
-rw-r--r--plugins/StopSpamPlus/src/eventhooker.cpp67
-rw-r--r--plugins/StopSpamPlus/src/eventhooker.h54
-rw-r--r--plugins/StopSpamPlus/src/events.cpp8
-rw-r--r--plugins/StopSpamPlus/src/stdafx.h5
-rw-r--r--plugins/StopSpamPlus/src/stopspam.cpp9
5 files changed, 13 insertions, 130 deletions
diff --git a/plugins/StopSpamPlus/src/eventhooker.cpp b/plugins/StopSpamPlus/src/eventhooker.cpp
deleted file mode 100644
index 8007779c01..0000000000
--- a/plugins/StopSpamPlus/src/eventhooker.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/* eventhooker.cpp
-* Copyright (C) Miklashevsky Roman
-*
-* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#include "stdafx.h"
-
-namespace miranda
-{
- namespace
- {
- std::list<EventHooker*> eventHookerList;
- }
-
- EventHooker::EventHooker(std::string name, MIRANDAHOOK fun) : name_(name), fun_(fun), handle_(0)
- {
- eventHookerList.push_back(this);
- }
-
- EventHooker::~EventHooker()
- {
- eventHookerList.remove(this);
- }
-
- void EventHooker::Hook()
- {
- handle_ = HookEvent(name_.c_str(), fun_);
- }
-
- void EventHooker::Unhook()
- {
- if (handle_)
- {
- UnhookEvent(handle_);
- handle_ = 0;
- }
- }
-
- void EventHooker::HookAll()
- {
- for (std::list<EventHooker*>::iterator it = eventHookerList.begin(); it != eventHookerList.end(); ++it)
- {
- (*it)->Hook();
- }
- }
-
- void EventHooker::UnhookAll()
- {
- for (std::list<EventHooker*>::iterator it = eventHookerList.begin(); it != eventHookerList.end(); ++it)
- {
- (*it)->Unhook();
- }
- }
-}
diff --git a/plugins/StopSpamPlus/src/eventhooker.h b/plugins/StopSpamPlus/src/eventhooker.h
deleted file mode 100644
index 7536671ca3..0000000000
--- a/plugins/StopSpamPlus/src/eventhooker.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* eventhooker.h - Helper for hooking events in Miranda.
-* Copyright (C) Miklashevsky Roman
-*
-* To hook event just write
-* MIRANDA_HOOK_EVENT('name of the event', wParam, lParam) { 'your code' }
-* Include following in your Load function
-* miranda::EventHooker::HookAll();
-* And following in your Unload function
-* miranda::EventHooker::UnhookAll();
-* That's all
-*
-* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#ifndef EVENTHOOKER_H_C8EAA58A_7C4D_45f7_A88E_0E41FE93754D
-#define EVENTHOOKER_H_C8EAA58A_7C4D_45f7_A88E_0E41FE93754D
-
-namespace miranda
-{
-
-#define MIRANDA_HOOK_EVENT(NAME, WPARAMNAME, LPARAMNAME) \
- int NAME##_Handler(WPARAM,LPARAM);\
- miranda::EventHooker NAME##_Hooker(NAME, NAME##_Handler);\
- int NAME##_Handler(WPARAM WPARAMNAME, LPARAM LPARAMNAME)
-
- struct EventHooker
- {
- EventHooker(std::string name, MIRANDAHOOK fun);
- ~EventHooker();
- void Hook();
- void Unhook();
- static void HookAll();
- static void UnhookAll();
- private:
- std::string name_;
- MIRANDAHOOK fun_;
- HANDLE handle_;
- };
-
-}
-
-#endif
diff --git a/plugins/StopSpamPlus/src/events.cpp b/plugins/StopSpamPlus/src/events.cpp
index b7a08422ab..a926efd551 100644
--- a/plugins/StopSpamPlus/src/events.cpp
+++ b/plugins/StopSpamPlus/src/events.cpp
@@ -1,6 +1,6 @@
#include "stdafx.h"
-MIRANDA_HOOK_EVENT(ME_DB_EVENT_ADDED, wParam, lParam)
+int OnDbEventAdded(WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(wParam);
MEVENT hDbEvent = (MEVENT)lParam;
@@ -46,7 +46,7 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_ADDED, wParam, lParam)
return 0;
}
-MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l)
+int OnDbEventFilterAdd(WPARAM w, LPARAM l)
{
MCONTACT hContact = (MCONTACT)w;
DBEVENTINFO *dbei = (DBEVENTINFO*)l;
@@ -161,7 +161,7 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l)
return 1;
}
-MIRANDA_HOOK_EVENT(ME_OPT_INITIALISE, w, l)
+int OnOptInit(WPARAM w, LPARAM l)
{
UNREFERENCED_PARAMETER(l);
@@ -188,7 +188,7 @@ MIRANDA_HOOK_EVENT(ME_OPT_INITIALISE, w, l)
return 0;
}
-MIRANDA_HOOK_EVENT(ME_DB_CONTACT_SETTINGCHANGED, hContact, l)
+int OnDbContactSettingchanged(WPARAM hContact, LPARAM l)
{
DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)l;
diff --git a/plugins/StopSpamPlus/src/stdafx.h b/plugins/StopSpamPlus/src/stdafx.h
index b326d51369..44c3d49d29 100644
--- a/plugins/StopSpamPlus/src/stdafx.h
+++ b/plugins/StopSpamPlus/src/stdafx.h
@@ -25,7 +25,6 @@
typedef std::wstring tstring;
#define PREF_TCHAR2 PREF_UTF
-#include "eventhooker.h"
#include "version.h"
#include "resource.h"
#include "settings.h"
@@ -54,4 +53,8 @@ tstring trim(tstring const &tstr, tstring const &trimChars = L" \f\n\r\t\v");
INT_PTR IsContactPassed(WPARAM wParam, LPARAM /*lParam*/);
INT_PTR RemoveTempContacts(WPARAM wParam,LPARAM lParam);
int OnSystemModulesLoaded(WPARAM wParam, LPARAM lParam);
+int OnDbEventAdded(WPARAM wParam, LPARAM lParam);
+int OnDbEventFilterAdd(WPARAM w, LPARAM l);
+int OnOptInit(WPARAM w, LPARAM l);
+int OnDbContactSettingchanged(WPARAM hContact, LPARAM l);
#endif
diff --git a/plugins/StopSpamPlus/src/stopspam.cpp b/plugins/StopSpamPlus/src/stopspam.cpp
index 9992a8915f..3409b6d8e8 100644
--- a/plugins/StopSpamPlus/src/stopspam.cpp
+++ b/plugins/StopSpamPlus/src/stopspam.cpp
@@ -44,7 +44,11 @@ extern "C" int __declspec(dllexport) Load(void)
CreateServiceFunction(MS_STOPSPAM_CONTACTPASSED, IsContactPassed);
HookEvent(ME_SYSTEM_MODULESLOADED, OnSystemModulesLoaded);
-
+ HookEvent(ME_DB_EVENT_ADDED, OnDbEventAdded);
+ HookEvent(ME_DB_EVENT_FILTER_ADD, OnDbEventFilterAdd);
+ HookEvent(ME_OPT_INITIALISE, OnOptInit);
+ HookEvent(ME_DB_CONTACT_SETTINGCHANGED, OnDbContactSettingchanged);
+
// Add deliting temporary contacts
CreateServiceFunction(MS_STOPSPAM_REMTEMPCONTACTS, RemoveTempContacts);
@@ -57,14 +61,11 @@ extern "C" int __declspec(dllexport) Load(void)
mi.pszService = pluginName"/RemoveTempContacts";
Menu_AddMainMenuItem(&mi);
- miranda::EventHooker::HookAll();
return 0;
}
extern "C" int __declspec(dllexport) Unload(void)
{
- miranda::EventHooker::UnhookAll();
-
delete plSets;
return 0;
} \ No newline at end of file