summaryrefslogtreecommitdiff
path: root/plugins/!NotAdopted/WinterSpeak/speak/announce/event_information.cpp
blob: bf326e5cfb3b41f28ecac0d9a3c4ee7e5b0d1a89 (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
//==============================================================================
// 	Miranda Speak Plugin, © 2002 Ryan Winter
//==============================================================================

#pragma warning(disable:4786)

#include "event_information.h"
#include "speak.h"

#include <general/debug/debug.h>

//------------------------------------------------------------------------------
// public:
//------------------------------------------------------------------------------
EventInformation::EventInformation()
	:
	m_event_strings(),
	m_event_info()
{
	CLASSCERR("EventInformation::EventInformation");

	// insert the event strings into a map for easy access
	m_event_strings[EVENTTYPE_MESSAGE]     
        = Translate("incoming message from %u");
	m_event_strings[EVENTTYPE_URL]         
        = Translate("incoming U R L from %u");
	m_event_strings[EVENTTYPE_ADDED]       
        = Translate("you have been added to %u's contact list");
	m_event_strings[EVENTTYPE_AUTHREQUEST]
        = Translate("%u requests your authorization");
	m_event_strings[EVENTTYPE_FILE]        
        = Translate("there is an incoming file from %u");

	ZeroMemory(&m_event_info, sizeof(m_event_info));
}

//------------------------------------------------------------------------------
EventInformation::~EventInformation()
{
	CLASSCERR("EventInformation::~EventInformation");
}

//------------------------------------------------------------------------------
bool
EventInformation::isValidEvent(HANDLE event)
{
	CLASSCERR("EventInformation::isValidEvent()");

	// clean up the old event
	if (m_event_info.pBlob)
	{
		delete m_event_info.pBlob;
	}
	ZeroMemory(&m_event_info, sizeof(m_event_info));

	// find out and assign the space we need for the new event
	m_event_info.cbSize = sizeof(m_event_info);
	m_event_info.cbBlob = CallService(MS_DB_EVENT_GETBLOBSIZE, 
		reinterpret_cast<LPARAM>(event), 0);

    if (-1 == m_event_info.cbBlob)
    {
        return false;
    }

	m_event_info.pBlob = new unsigned char[m_event_info.cbBlob];

	// get the event info
	CallService(MS_DB_EVENT_GET, reinterpret_cast<LPARAM>(event), 
		reinterpret_cast<LPARAM>(&m_event_info));

	// if the event has already been read or was sent by me then exit
	if (m_event_info.flags & (DBEF_SENT | DBEF_READ))
	{
		return false;
	}

	// if the event string doesn't exist in our list then exit
	if (m_event_strings.find(m_event_info.eventType) == m_event_strings.end())
	{
		return false;
	}

	// event was good
	return true;
}

//------------------------------------------------------------------------------
std::string 
EventInformation::getMessage()
{
	CLASSCERR("EventInformation::getMessage");

    const std::string intro = Translate("%u says");

	return intro + " " + (char *)m_event_info.pBlob;
}

//------------------------------------------------------------------------------
unsigned int 
EventInformation::getMessageSize()
{
	CLASSCERR("EventInformation::getMessageSize");

	return std::string((char *)m_event_info.pBlob).size();
}

//------------------------------------------------------------------------------
std::string 
EventInformation::eventString()
{
	CLASSCERR("EventInformation::eventString");

	return m_event_strings[m_event_info.eventType];
}

//==============================================================================