summaryrefslogtreecommitdiff
path: root/plugins/WinterSpeak/src/UserInformation.cpp
blob: 7163e9b23ebac261656e171123133b7be84620dc (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
#include "Common.h"
#include "UserInformation.h"


UserInformation::UserInformation() : m_status_info(), m_status_strings() {
	// insert the status strings into a map for easy access
	m_status_strings[ID_STATUS_OFFLINE]   = L"%u is now offline";
	m_status_strings[ID_STATUS_ONLINE]    = L"%u is now online";
	m_status_strings[ID_STATUS_AWAY]      = L"%u is away";
	m_status_strings[ID_STATUS_INVISIBLE] = L"%u is invisible";
	m_status_strings[ID_STATUS_NA]        = L"%u is not available";
	m_status_strings[ID_STATUS_DND]       = L"%u does not want to be disturbed";
	m_status_strings[ID_STATUS_OCCUPIED]  = L"%u is occupied";
	m_status_strings[ID_STATUS_FREECHAT]  = L"%u is free for chat";
}

//------------------------------------------------------------------------------
UserInformation::~UserInformation()
{
}

//------------------------------------------------------------------------------
bool UserInformation::updateStatus(HANDLE user, int status)
{
	bool ret = false;

    // if the user exists and their status hasn't changed, then return false
	if ((m_status_info.find(user) != m_status_info.end())
		&& (m_status_info[user] != status))
	{
		ret = true;
	}

	// update the status
	m_status_info[user] = status;

	return ret;
}

//------------------------------------------------------------------------------
std::wstring UserInformation::statusString(HANDLE user)
{
	return m_status_strings[m_status_info[user]];
}

//------------------------------------------------------------------------------
std::wstring UserInformation::statusModeString(HANDLE user)
{
	int status = CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, m_status_info[user], 0);

    if (NULL == status)
    {
        return L"";
    }

    return reinterpret_cast<WCHAR *>(status);
}

//------------------------------------------------------------------------------
void UserInformation::insertName(std::wstring &str, HANDLE user) const
{
	// insert the user's name into the string
	str.replace(str.find(L"%u"), 2, nameString(user));
}

//------------------------------------------------------------------------------
std::wstring UserInformation::nameString(HANDLE user) const
{
	//WCHAR *ret = reinterpret_cast<WCHAR *>(CallService(MS_CLIST_GETCONTACTDISPLAYNAME, reinterpret_cast<unsigned int>(user), 0));
	char* ret = (char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, WPARAM(user), 0);
    if (0 == ret)
    {
        return L"";
    }
    return TranslateW(mir_a2t_cp(ret, CP_UTF8));
}

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