summaryrefslogtreecommitdiff
path: root/!NotAdopted/XSoundNotify/xsn_utils.cpp
blob: d597776e8d1ea8c235a16178f4014cc4311f37e5 (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
#include "xsn_utils.h"
#include <m_protocols.h>
#include <boost/lexical_cast.hpp>

void initModuleConvertTable(ModuleConvertTable & table)
{
	int number = 0;
	// may be need to free PROTOACCOUNT, but did't found information about it
	PROTOACCOUNT ** accounts; 
	ProtoEnumAccounts(&number, &accounts);
	for (int i = 0; i < number; ++i)
		table[ModuleString(accounts[i]->szModuleName)] = ProtocolString(accounts[i]->szProtoName);
}

bool isReceiveMessage(LPARAM event)
{
	DBEVENTINFO info = { sizeof(info) };	
	CallService(MS_DB_EVENT_GET, event, (LPARAM)&info);
	// i don't understand why it works and how it works, but it works correctly - practice way (ìåòîäîì òûêà)
	// so, i think correct condition would be : eventType == EVENTTYPE_MESSAGE && info.flags & DBEF_READ, but it really isn't
	return !(((info.eventType != EVENTTYPE_MESSAGE) && !(info.flags & DBEF_READ)) || (info.flags & DBEF_SENT));
}

xsn_string getContactSound(HANDLE contact)
{
	XSN_Variant sound;
	DBGetContactSettingTString(contact, XSN_ModuleInfo::name(), XSN_ModuleInfo::soundSetting(), &sound);
	return sound.toString();	
}

ModuleString getContactModule(HANDLE contact)
{
	char * proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)contact, 0);
	if (proto == nullptr)
		throw std::runtime_error("MS_PROTO_GETCONTACTBASEPROTO failed");
	return ModuleString(proto);
}

xsn_string getIcqContactId(HANDLE contact, const ModuleString & module)
{
	XSN_Variant nick;
	DBGetContactSettingTString(contact, module.c_str(), "CustomNick", &nick);
	if (nick.empty())
		DBGetContactSettingTString(contact, module.c_str(), "Nick", &nick);
	DWORD uin = DBGetContactSettingDword(contact, module.c_str(), "UIN", 0);
	xsn_string uinStr = boost::lexical_cast<xsn_string>(uin);
	if (nick.empty())
		return uinStr;
	return nick.toString() + TEXT(" (") + uinStr + TEXT(")");
}

xsn_string getJabberContactId(HANDLE contact, const ModuleString & module)
{
	XSN_Variant jid, nick;
	DBGetContactSettingTString(contact, module.c_str(), "jid", &jid);
	DBGetContactSettingTString(contact, "CList", "MyHandle", &nick);
	if (nick.empty())
		return jid.toString();
	return nick.toString() + TEXT(" (") + jid.toString() + TEXT(")");
}